
bin/kernel:     file format elf64-littleriscv


Disassembly of section .text:

ffffffffc0200000 <kern_entry>:
    .globl kern_entry
kern_entry:
    # a0: hartid
    # a1: dtb physical address
    # save hartid and dtb address
    la t0, boot_hartid
ffffffffc0200000:	00005297          	auipc	t0,0x5
ffffffffc0200004:	00028293          	mv	t0,t0
    sd a0, 0(t0)
ffffffffc0200008:	00a2b023          	sd	a0,0(t0) # ffffffffc0205000 <boot_hartid>
    la t0, boot_dtb
ffffffffc020000c:	00005297          	auipc	t0,0x5
ffffffffc0200010:	ffc28293          	addi	t0,t0,-4 # ffffffffc0205008 <boot_dtb>
    sd a1, 0(t0)
ffffffffc0200014:	00b2b023          	sd	a1,0(t0)

    # t0 := 三级页表的虚拟地址
    lui     t0, %hi(boot_page_table_sv39)
ffffffffc0200018:	c02042b7          	lui	t0,0xc0204
    # t1 := 0xffffffff40000000 即虚实映射偏移量
    li      t1, 0xffffffffc0000000 - 0x80000000
ffffffffc020001c:	ffd0031b          	addiw	t1,zero,-3
ffffffffc0200020:	037a                	slli	t1,t1,0x1e
    # t0 减去虚实映射偏移量 0xffffffff40000000，变为三级页表的物理地址
    sub     t0, t0, t1
ffffffffc0200022:	406282b3          	sub	t0,t0,t1
    # t0 >>= 12，变为三级页表的物理页号
    srli    t0, t0, 12
ffffffffc0200026:	00c2d293          	srli	t0,t0,0xc

    # t1 := 8 << 60，设置 satp 的 MODE 字段为 Sv39
    li      t1, 8 << 60
ffffffffc020002a:	fff0031b          	addiw	t1,zero,-1
ffffffffc020002e:	137e                	slli	t1,t1,0x3f
    # 将刚才计算出的预设三级页表物理页号附加到 satp 中
    or      t0, t0, t1
ffffffffc0200030:	0062e2b3          	or	t0,t0,t1
    # 将算出的 t0(即新的MODE|页表基址物理页号) 覆盖到 satp 中
    csrw    satp, t0
ffffffffc0200034:	18029073          	csrw	satp,t0
    # 使用 sfence.vma 指令刷新 TLB
    sfence.vma
ffffffffc0200038:	12000073          	sfence.vma
    # 从此，我们给内核搭建出了一个完美的虚拟内存空间！
    #nop # 可能映射的位置有些bug。。插入一个nop
    
    # 我们在虚拟内存空间中：随意将 sp 设置为虚拟地址！
    lui sp, %hi(bootstacktop)
ffffffffc020003c:	c0204137          	lui	sp,0xc0204

    # 我们在虚拟内存空间中：随意跳转到虚拟地址！
    # 跳转到 kern_init
    lui t0, %hi(kern_init)
ffffffffc0200040:	c02002b7          	lui	t0,0xc0200
    addi t0, t0, %lo(kern_init)
ffffffffc0200044:	0d628293          	addi	t0,t0,214 # ffffffffc02000d6 <kern_init>
    jr t0
ffffffffc0200048:	8282                	jr	t0

ffffffffc020004a <print_kerninfo>:
/* *
 * print_kerninfo - print the information about kernel, including the location
 * of kernel entry, the start addresses of data and text segements, the start
 * address of free memory and how many memory that kernel has used.
 * */
void print_kerninfo(void) {
ffffffffc020004a:	1141                	addi	sp,sp,-16 # ffffffffc0203ff0 <bootstack+0x1ff0>
    extern char etext[], edata[], end[];
    cprintf("Special kernel symbols:\n");
ffffffffc020004c:	00001517          	auipc	a0,0x1
ffffffffc0200050:	04c50513          	addi	a0,a0,76 # ffffffffc0201098 <etext+0x4>
void print_kerninfo(void) {
ffffffffc0200054:	e406                	sd	ra,8(sp)
    cprintf("Special kernel symbols:\n");
ffffffffc0200056:	0f2000ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("  entry  0x%016lx (virtual)\n", (uintptr_t)kern_init);
ffffffffc020005a:	00000597          	auipc	a1,0x0
ffffffffc020005e:	07c58593          	addi	a1,a1,124 # ffffffffc02000d6 <kern_init>
ffffffffc0200062:	00001517          	auipc	a0,0x1
ffffffffc0200066:	05650513          	addi	a0,a0,86 # ffffffffc02010b8 <etext+0x24>
ffffffffc020006a:	0de000ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("  etext  0x%016lx (virtual)\n", etext);
ffffffffc020006e:	00001597          	auipc	a1,0x1
ffffffffc0200072:	02658593          	addi	a1,a1,38 # ffffffffc0201094 <etext>
ffffffffc0200076:	00001517          	auipc	a0,0x1
ffffffffc020007a:	06250513          	addi	a0,a0,98 # ffffffffc02010d8 <etext+0x44>
ffffffffc020007e:	0ca000ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("  edata  0x%016lx (virtual)\n", edata);
ffffffffc0200082:	00005597          	auipc	a1,0x5
ffffffffc0200086:	f9658593          	addi	a1,a1,-106 # ffffffffc0205018 <buddy_sys>
ffffffffc020008a:	00001517          	auipc	a0,0x1
ffffffffc020008e:	06e50513          	addi	a0,a0,110 # ffffffffc02010f8 <etext+0x64>
ffffffffc0200092:	0b6000ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("  end    0x%016lx (virtual)\n", end);
ffffffffc0200096:	00005597          	auipc	a1,0x5
ffffffffc020009a:	08258593          	addi	a1,a1,130 # ffffffffc0205118 <end>
ffffffffc020009e:	00001517          	auipc	a0,0x1
ffffffffc02000a2:	07a50513          	addi	a0,a0,122 # ffffffffc0201118 <etext+0x84>
ffffffffc02000a6:	0a2000ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("Kernel executable memory footprint: %dKB\n",
            (end - (char*)kern_init + 1023) / 1024);
ffffffffc02000aa:	00000717          	auipc	a4,0x0
ffffffffc02000ae:	02c70713          	addi	a4,a4,44 # ffffffffc02000d6 <kern_init>
ffffffffc02000b2:	00005797          	auipc	a5,0x5
ffffffffc02000b6:	46578793          	addi	a5,a5,1125 # ffffffffc0205517 <end+0x3ff>
ffffffffc02000ba:	8f99                	sub	a5,a5,a4
    cprintf("Kernel executable memory footprint: %dKB\n",
ffffffffc02000bc:	43f7d593          	srai	a1,a5,0x3f
}
ffffffffc02000c0:	60a2                	ld	ra,8(sp)
    cprintf("Kernel executable memory footprint: %dKB\n",
ffffffffc02000c2:	3ff5f593          	andi	a1,a1,1023
ffffffffc02000c6:	95be                	add	a1,a1,a5
ffffffffc02000c8:	85a9                	srai	a1,a1,0xa
ffffffffc02000ca:	00001517          	auipc	a0,0x1
ffffffffc02000ce:	06e50513          	addi	a0,a0,110 # ffffffffc0201138 <etext+0xa4>
}
ffffffffc02000d2:	0141                	addi	sp,sp,16
    cprintf("Kernel executable memory footprint: %dKB\n",
ffffffffc02000d4:	a895                	j	ffffffffc0200148 <cprintf>

ffffffffc02000d6 <kern_init>:

int kern_init(void) {
    extern char edata[], end[];
    memset(edata, 0, end - edata);
ffffffffc02000d6:	00005517          	auipc	a0,0x5
ffffffffc02000da:	f4250513          	addi	a0,a0,-190 # ffffffffc0205018 <buddy_sys>
ffffffffc02000de:	00005617          	auipc	a2,0x5
ffffffffc02000e2:	03a60613          	addi	a2,a2,58 # ffffffffc0205118 <end>
int kern_init(void) {
ffffffffc02000e6:	1141                	addi	sp,sp,-16
    memset(edata, 0, end - edata);
ffffffffc02000e8:	8e09                	sub	a2,a2,a0
ffffffffc02000ea:	4581                	li	a1,0
int kern_init(void) {
ffffffffc02000ec:	e406                	sd	ra,8(sp)
    memset(edata, 0, end - edata);
ffffffffc02000ee:	795000ef          	jal	ffffffffc0201082 <memset>
    dtb_init();
ffffffffc02000f2:	136000ef          	jal	ffffffffc0200228 <dtb_init>
    cons_init();  // init the console
ffffffffc02000f6:	128000ef          	jal	ffffffffc020021e <cons_init>
    const char *message = "(THU.CST) os is loading ...\0";
    //cprintf("%s\n\n", message);
    cputs(message);
ffffffffc02000fa:	00001517          	auipc	a0,0x1
ffffffffc02000fe:	5ce50513          	addi	a0,a0,1486 # ffffffffc02016c8 <etext+0x634>
ffffffffc0200102:	07a000ef          	jal	ffffffffc020017c <cputs>

    print_kerninfo();
ffffffffc0200106:	f45ff0ef          	jal	ffffffffc020004a <print_kerninfo>

    // grade_backtrace();
    pmm_init();  // init physical memory management
ffffffffc020010a:	12f000ef          	jal	ffffffffc0200a38 <pmm_init>

    /* do nothing */
    while (1)
ffffffffc020010e:	a001                	j	ffffffffc020010e <kern_init+0x38>

ffffffffc0200110 <cputch>:
/* *
 * cputch - writes a single character @c to stdout, and it will
 * increace the value of counter pointed by @cnt.
 * */
static void
cputch(int c, int *cnt) {
ffffffffc0200110:	1101                	addi	sp,sp,-32
ffffffffc0200112:	ec06                	sd	ra,24(sp)
ffffffffc0200114:	e42e                	sd	a1,8(sp)
    cons_putc(c);
ffffffffc0200116:	10a000ef          	jal	ffffffffc0200220 <cons_putc>
    (*cnt) ++;
ffffffffc020011a:	65a2                	ld	a1,8(sp)
}
ffffffffc020011c:	60e2                	ld	ra,24(sp)
    (*cnt) ++;
ffffffffc020011e:	419c                	lw	a5,0(a1)
ffffffffc0200120:	2785                	addiw	a5,a5,1
ffffffffc0200122:	c19c                	sw	a5,0(a1)
}
ffffffffc0200124:	6105                	addi	sp,sp,32
ffffffffc0200126:	8082                	ret

ffffffffc0200128 <vcprintf>:
 *
 * Call this function if you are already dealing with a va_list.
 * Or you probably want cprintf() instead.
 * */
int
vcprintf(const char *fmt, va_list ap) {
ffffffffc0200128:	1101                	addi	sp,sp,-32
ffffffffc020012a:	862a                	mv	a2,a0
ffffffffc020012c:	86ae                	mv	a3,a1
    int cnt = 0;
    vprintfmt((void*)cputch, &cnt, fmt, ap);
ffffffffc020012e:	00000517          	auipc	a0,0x0
ffffffffc0200132:	fe250513          	addi	a0,a0,-30 # ffffffffc0200110 <cputch>
ffffffffc0200136:	006c                	addi	a1,sp,12
vcprintf(const char *fmt, va_list ap) {
ffffffffc0200138:	ec06                	sd	ra,24(sp)
    int cnt = 0;
ffffffffc020013a:	c602                	sw	zero,12(sp)
    vprintfmt((void*)cputch, &cnt, fmt, ap);
ffffffffc020013c:	337000ef          	jal	ffffffffc0200c72 <vprintfmt>
    return cnt;
}
ffffffffc0200140:	60e2                	ld	ra,24(sp)
ffffffffc0200142:	4532                	lw	a0,12(sp)
ffffffffc0200144:	6105                	addi	sp,sp,32
ffffffffc0200146:	8082                	ret

ffffffffc0200148 <cprintf>:
 *
 * The return value is the number of characters which would be
 * written to stdout.
 * */
int
cprintf(const char *fmt, ...) {
ffffffffc0200148:	711d                	addi	sp,sp,-96
    va_list ap;
    int cnt;
    va_start(ap, fmt);
ffffffffc020014a:	02810313          	addi	t1,sp,40
cprintf(const char *fmt, ...) {
ffffffffc020014e:	f42e                	sd	a1,40(sp)
ffffffffc0200150:	f832                	sd	a2,48(sp)
ffffffffc0200152:	fc36                	sd	a3,56(sp)
    vprintfmt((void*)cputch, &cnt, fmt, ap);
ffffffffc0200154:	862a                	mv	a2,a0
ffffffffc0200156:	004c                	addi	a1,sp,4
ffffffffc0200158:	00000517          	auipc	a0,0x0
ffffffffc020015c:	fb850513          	addi	a0,a0,-72 # ffffffffc0200110 <cputch>
ffffffffc0200160:	869a                	mv	a3,t1
cprintf(const char *fmt, ...) {
ffffffffc0200162:	ec06                	sd	ra,24(sp)
ffffffffc0200164:	e0ba                	sd	a4,64(sp)
ffffffffc0200166:	e4be                	sd	a5,72(sp)
ffffffffc0200168:	e8c2                	sd	a6,80(sp)
ffffffffc020016a:	ecc6                	sd	a7,88(sp)
    int cnt = 0;
ffffffffc020016c:	c202                	sw	zero,4(sp)
    va_start(ap, fmt);
ffffffffc020016e:	e41a                	sd	t1,8(sp)
    vprintfmt((void*)cputch, &cnt, fmt, ap);
ffffffffc0200170:	303000ef          	jal	ffffffffc0200c72 <vprintfmt>
    cnt = vcprintf(fmt, ap);
    va_end(ap);
    return cnt;
}
ffffffffc0200174:	60e2                	ld	ra,24(sp)
ffffffffc0200176:	4512                	lw	a0,4(sp)
ffffffffc0200178:	6125                	addi	sp,sp,96
ffffffffc020017a:	8082                	ret

ffffffffc020017c <cputs>:
/* *
 * cputs- writes the string pointed by @str to stdout and
 * appends a newline character.
 * */
int
cputs(const char *str) {
ffffffffc020017c:	1101                	addi	sp,sp,-32
ffffffffc020017e:	e822                	sd	s0,16(sp)
ffffffffc0200180:	ec06                	sd	ra,24(sp)
ffffffffc0200182:	842a                	mv	s0,a0
    int cnt = 0;
    char c;
    while ((c = *str ++) != '\0') {
ffffffffc0200184:	00054503          	lbu	a0,0(a0)
ffffffffc0200188:	c51d                	beqz	a0,ffffffffc02001b6 <cputs+0x3a>
ffffffffc020018a:	e426                	sd	s1,8(sp)
ffffffffc020018c:	0405                	addi	s0,s0,1
    int cnt = 0;
ffffffffc020018e:	4481                	li	s1,0
    cons_putc(c);
ffffffffc0200190:	090000ef          	jal	ffffffffc0200220 <cons_putc>
    while ((c = *str ++) != '\0') {
ffffffffc0200194:	00044503          	lbu	a0,0(s0)
ffffffffc0200198:	0405                	addi	s0,s0,1
ffffffffc020019a:	87a6                	mv	a5,s1
    (*cnt) ++;
ffffffffc020019c:	2485                	addiw	s1,s1,1
    while ((c = *str ++) != '\0') {
ffffffffc020019e:	f96d                	bnez	a0,ffffffffc0200190 <cputs+0x14>
    cons_putc(c);
ffffffffc02001a0:	4529                	li	a0,10
    (*cnt) ++;
ffffffffc02001a2:	0027841b          	addiw	s0,a5,2
ffffffffc02001a6:	64a2                	ld	s1,8(sp)
    cons_putc(c);
ffffffffc02001a8:	078000ef          	jal	ffffffffc0200220 <cons_putc>
        cputch(c, &cnt);
    }
    cputch('\n', &cnt);
    return cnt;
}
ffffffffc02001ac:	60e2                	ld	ra,24(sp)
ffffffffc02001ae:	8522                	mv	a0,s0
ffffffffc02001b0:	6442                	ld	s0,16(sp)
ffffffffc02001b2:	6105                	addi	sp,sp,32
ffffffffc02001b4:	8082                	ret
    cons_putc(c);
ffffffffc02001b6:	4529                	li	a0,10
ffffffffc02001b8:	068000ef          	jal	ffffffffc0200220 <cons_putc>
    while ((c = *str ++) != '\0') {
ffffffffc02001bc:	4405                	li	s0,1
}
ffffffffc02001be:	60e2                	ld	ra,24(sp)
ffffffffc02001c0:	8522                	mv	a0,s0
ffffffffc02001c2:	6442                	ld	s0,16(sp)
ffffffffc02001c4:	6105                	addi	sp,sp,32
ffffffffc02001c6:	8082                	ret

ffffffffc02001c8 <__panic>:
 * __panic - __panic is called on unresolvable fatal errors. it prints
 * "panic: 'message'", and then enters the kernel monitor.
 * */
void
__panic(const char *file, int line, const char *fmt, ...) {
    if (is_panic) {
ffffffffc02001c8:	00005317          	auipc	t1,0x5
ffffffffc02001cc:	f0832303          	lw	t1,-248(t1) # ffffffffc02050d0 <is_panic>
__panic(const char *file, int line, const char *fmt, ...) {
ffffffffc02001d0:	715d                	addi	sp,sp,-80
ffffffffc02001d2:	ec06                	sd	ra,24(sp)
ffffffffc02001d4:	f436                	sd	a3,40(sp)
ffffffffc02001d6:	f83a                	sd	a4,48(sp)
ffffffffc02001d8:	fc3e                	sd	a5,56(sp)
ffffffffc02001da:	e0c2                	sd	a6,64(sp)
ffffffffc02001dc:	e4c6                	sd	a7,72(sp)
    if (is_panic) {
ffffffffc02001de:	00030363          	beqz	t1,ffffffffc02001e4 <__panic+0x1c>
    vcprintf(fmt, ap);
    cprintf("\n");
    va_end(ap);

panic_dead:
    while (1) {
ffffffffc02001e2:	a001                	j	ffffffffc02001e2 <__panic+0x1a>
    is_panic = 1;
ffffffffc02001e4:	4705                	li	a4,1
    va_start(ap, fmt);
ffffffffc02001e6:	103c                	addi	a5,sp,40
ffffffffc02001e8:	e822                	sd	s0,16(sp)
ffffffffc02001ea:	8432                	mv	s0,a2
ffffffffc02001ec:	862e                	mv	a2,a1
ffffffffc02001ee:	85aa                	mv	a1,a0
    cprintf("kernel panic at %s:%d:\n    ", file, line);
ffffffffc02001f0:	00001517          	auipc	a0,0x1
ffffffffc02001f4:	f7850513          	addi	a0,a0,-136 # ffffffffc0201168 <etext+0xd4>
    is_panic = 1;
ffffffffc02001f8:	00005697          	auipc	a3,0x5
ffffffffc02001fc:	ece6ac23          	sw	a4,-296(a3) # ffffffffc02050d0 <is_panic>
    va_start(ap, fmt);
ffffffffc0200200:	e43e                	sd	a5,8(sp)
    cprintf("kernel panic at %s:%d:\n    ", file, line);
ffffffffc0200202:	f47ff0ef          	jal	ffffffffc0200148 <cprintf>
    vcprintf(fmt, ap);
ffffffffc0200206:	65a2                	ld	a1,8(sp)
ffffffffc0200208:	8522                	mv	a0,s0
ffffffffc020020a:	f1fff0ef          	jal	ffffffffc0200128 <vcprintf>
    cprintf("\n");
ffffffffc020020e:	00001517          	auipc	a0,0x1
ffffffffc0200212:	f7a50513          	addi	a0,a0,-134 # ffffffffc0201188 <etext+0xf4>
ffffffffc0200216:	f33ff0ef          	jal	ffffffffc0200148 <cprintf>
ffffffffc020021a:	6442                	ld	s0,16(sp)
ffffffffc020021c:	b7d9                	j	ffffffffc02001e2 <__panic+0x1a>

ffffffffc020021e <cons_init>:

/* serial_intr - try to feed input characters from serial port */
void serial_intr(void) {}

/* cons_init - initializes the console devices */
void cons_init(void) {}
ffffffffc020021e:	8082                	ret

ffffffffc0200220 <cons_putc>:

/* cons_putc - print a single character @c to console devices */
void cons_putc(int c) { sbi_console_putchar((unsigned char)c); }
ffffffffc0200220:	0ff57513          	zext.b	a0,a0
ffffffffc0200224:	5b50006f          	j	ffffffffc0200fd8 <sbi_console_putchar>

ffffffffc0200228 <dtb_init>:

// 保存解析出的系统物理内存信息
static uint64_t memory_base = 0;
static uint64_t memory_size = 0;

void dtb_init(void) {
ffffffffc0200228:	7179                	addi	sp,sp,-48
    cprintf("DTB Init\n");
ffffffffc020022a:	00001517          	auipc	a0,0x1
ffffffffc020022e:	f6650513          	addi	a0,a0,-154 # ffffffffc0201190 <etext+0xfc>
void dtb_init(void) {
ffffffffc0200232:	f406                	sd	ra,40(sp)
ffffffffc0200234:	f022                	sd	s0,32(sp)
    cprintf("DTB Init\n");
ffffffffc0200236:	f13ff0ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("HartID: %ld\n", boot_hartid);
ffffffffc020023a:	00005597          	auipc	a1,0x5
ffffffffc020023e:	dc65b583          	ld	a1,-570(a1) # ffffffffc0205000 <boot_hartid>
ffffffffc0200242:	00001517          	auipc	a0,0x1
ffffffffc0200246:	f5e50513          	addi	a0,a0,-162 # ffffffffc02011a0 <etext+0x10c>
    cprintf("DTB Address: 0x%lx\n", boot_dtb);
ffffffffc020024a:	00005417          	auipc	s0,0x5
ffffffffc020024e:	dbe40413          	addi	s0,s0,-578 # ffffffffc0205008 <boot_dtb>
    cprintf("HartID: %ld\n", boot_hartid);
ffffffffc0200252:	ef7ff0ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("DTB Address: 0x%lx\n", boot_dtb);
ffffffffc0200256:	600c                	ld	a1,0(s0)
ffffffffc0200258:	00001517          	auipc	a0,0x1
ffffffffc020025c:	f5850513          	addi	a0,a0,-168 # ffffffffc02011b0 <etext+0x11c>
ffffffffc0200260:	ee9ff0ef          	jal	ffffffffc0200148 <cprintf>
    
    if (boot_dtb == 0) {
ffffffffc0200264:	6018                	ld	a4,0(s0)
        cprintf("Error: DTB address is null\n");
ffffffffc0200266:	00001517          	auipc	a0,0x1
ffffffffc020026a:	f6250513          	addi	a0,a0,-158 # ffffffffc02011c8 <etext+0x134>
    if (boot_dtb == 0) {
ffffffffc020026e:	10070163          	beqz	a4,ffffffffc0200370 <dtb_init+0x148>
        return;
    }
    
    // 转换为虚拟地址
    uintptr_t dtb_vaddr = boot_dtb + PHYSICAL_MEMORY_OFFSET;
ffffffffc0200272:	57f5                	li	a5,-3
ffffffffc0200274:	07fa                	slli	a5,a5,0x1e
ffffffffc0200276:	973e                	add	a4,a4,a5
    const struct fdt_header *header = (const struct fdt_header *)dtb_vaddr;
    
    // 验证DTB
    uint32_t magic = fdt32_to_cpu(header->magic);
ffffffffc0200278:	431c                	lw	a5,0(a4)
    if (magic != 0xd00dfeed) {
ffffffffc020027a:	d00e06b7          	lui	a3,0xd00e0
ffffffffc020027e:	eed68693          	addi	a3,a3,-275 # ffffffffd00dfeed <end+0xfedadd5>
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200282:	0087d59b          	srliw	a1,a5,0x8
ffffffffc0200286:	0187961b          	slliw	a2,a5,0x18
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc020028a:	0187d51b          	srliw	a0,a5,0x18
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc020028e:	0ff5f593          	zext.b	a1,a1
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200292:	0107d79b          	srliw	a5,a5,0x10
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200296:	05c2                	slli	a1,a1,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200298:	8e49                	or	a2,a2,a0
ffffffffc020029a:	0ff7f793          	zext.b	a5,a5
ffffffffc020029e:	8dd1                	or	a1,a1,a2
ffffffffc02002a0:	07a2                	slli	a5,a5,0x8
ffffffffc02002a2:	8ddd                	or	a1,a1,a5
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02002a4:	00ff0837          	lui	a6,0xff0
    if (magic != 0xd00dfeed) {
ffffffffc02002a8:	0cd59863          	bne	a1,a3,ffffffffc0200378 <dtb_init+0x150>
        return;
    }
    
    // 提取内存信息
    uint64_t mem_base, mem_size;
    if (extract_memory_info(dtb_vaddr, header, &mem_base, &mem_size) == 0) {
ffffffffc02002ac:	4710                	lw	a2,8(a4)
ffffffffc02002ae:	4754                	lw	a3,12(a4)
    const char *strings_base = (const char *)(dtb_vaddr + strings_offset);
ffffffffc02002b0:	e84a                	sd	s2,16(sp)
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02002b2:	0086541b          	srliw	s0,a2,0x8
ffffffffc02002b6:	0086d79b          	srliw	a5,a3,0x8
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02002ba:	01865e1b          	srliw	t3,a2,0x18
ffffffffc02002be:	0186d89b          	srliw	a7,a3,0x18
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02002c2:	0186151b          	slliw	a0,a2,0x18
ffffffffc02002c6:	0186959b          	slliw	a1,a3,0x18
ffffffffc02002ca:	0104141b          	slliw	s0,s0,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02002ce:	0106561b          	srliw	a2,a2,0x10
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02002d2:	0107979b          	slliw	a5,a5,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02002d6:	0106d69b          	srliw	a3,a3,0x10
ffffffffc02002da:	01c56533          	or	a0,a0,t3
ffffffffc02002de:	0115e5b3          	or	a1,a1,a7
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02002e2:	01047433          	and	s0,s0,a6
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02002e6:	0ff67613          	zext.b	a2,a2
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02002ea:	0107f7b3          	and	a5,a5,a6
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02002ee:	0ff6f693          	zext.b	a3,a3
ffffffffc02002f2:	8c49                	or	s0,s0,a0
ffffffffc02002f4:	0622                	slli	a2,a2,0x8
ffffffffc02002f6:	8fcd                	or	a5,a5,a1
ffffffffc02002f8:	06a2                	slli	a3,a3,0x8
ffffffffc02002fa:	8c51                	or	s0,s0,a2
ffffffffc02002fc:	8fd5                	or	a5,a5,a3
    const uint32_t *struct_ptr = (const uint32_t *)(dtb_vaddr + struct_offset);
ffffffffc02002fe:	1402                	slli	s0,s0,0x20
    const char *strings_base = (const char *)(dtb_vaddr + strings_offset);
ffffffffc0200300:	1782                	slli	a5,a5,0x20
    const uint32_t *struct_ptr = (const uint32_t *)(dtb_vaddr + struct_offset);
ffffffffc0200302:	9001                	srli	s0,s0,0x20
    const char *strings_base = (const char *)(dtb_vaddr + strings_offset);
ffffffffc0200304:	9381                	srli	a5,a5,0x20
ffffffffc0200306:	ec26                	sd	s1,24(sp)
    int in_memory_node = 0;
ffffffffc0200308:	4301                	li	t1,0
        switch (token) {
ffffffffc020030a:	488d                	li	a7,3
    const uint32_t *struct_ptr = (const uint32_t *)(dtb_vaddr + struct_offset);
ffffffffc020030c:	943a                	add	s0,s0,a4
    const char *strings_base = (const char *)(dtb_vaddr + strings_offset);
ffffffffc020030e:	00e78933          	add	s2,a5,a4
        switch (token) {
ffffffffc0200312:	4e05                	li	t3,1
        uint32_t token = fdt32_to_cpu(*struct_ptr++);
ffffffffc0200314:	4018                	lw	a4,0(s0)
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200316:	0087579b          	srliw	a5,a4,0x8
ffffffffc020031a:	0187169b          	slliw	a3,a4,0x18
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc020031e:	0187561b          	srliw	a2,a4,0x18
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200322:	0107979b          	slliw	a5,a5,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200326:	0107571b          	srliw	a4,a4,0x10
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc020032a:	0107f7b3          	and	a5,a5,a6
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc020032e:	8ed1                	or	a3,a3,a2
ffffffffc0200330:	0ff77713          	zext.b	a4,a4
ffffffffc0200334:	8fd5                	or	a5,a5,a3
ffffffffc0200336:	0722                	slli	a4,a4,0x8
ffffffffc0200338:	8fd9                	or	a5,a5,a4
        switch (token) {
ffffffffc020033a:	05178763          	beq	a5,a7,ffffffffc0200388 <dtb_init+0x160>
        uint32_t token = fdt32_to_cpu(*struct_ptr++);
ffffffffc020033e:	0411                	addi	s0,s0,4
        switch (token) {
ffffffffc0200340:	00f8e963          	bltu	a7,a5,ffffffffc0200352 <dtb_init+0x12a>
ffffffffc0200344:	07c78d63          	beq	a5,t3,ffffffffc02003be <dtb_init+0x196>
ffffffffc0200348:	4709                	li	a4,2
ffffffffc020034a:	00e79763          	bne	a5,a4,ffffffffc0200358 <dtb_init+0x130>
ffffffffc020034e:	4301                	li	t1,0
ffffffffc0200350:	b7d1                	j	ffffffffc0200314 <dtb_init+0xec>
ffffffffc0200352:	4711                	li	a4,4
ffffffffc0200354:	fce780e3          	beq	a5,a4,ffffffffc0200314 <dtb_init+0xec>
        cprintf("  End:  0x%016lx\n", mem_base + mem_size - 1);
        // 保存到全局变量，供 PMM 查询
        memory_base = mem_base;
        memory_size = mem_size;
    } else {
        cprintf("Warning: Could not extract memory info from DTB\n");
ffffffffc0200358:	00001517          	auipc	a0,0x1
ffffffffc020035c:	f3850513          	addi	a0,a0,-200 # ffffffffc0201290 <etext+0x1fc>
ffffffffc0200360:	de9ff0ef          	jal	ffffffffc0200148 <cprintf>
    }
    cprintf("DTB init completed\n");
ffffffffc0200364:	64e2                	ld	s1,24(sp)
ffffffffc0200366:	6942                	ld	s2,16(sp)
ffffffffc0200368:	00001517          	auipc	a0,0x1
ffffffffc020036c:	f6050513          	addi	a0,a0,-160 # ffffffffc02012c8 <etext+0x234>
}
ffffffffc0200370:	7402                	ld	s0,32(sp)
ffffffffc0200372:	70a2                	ld	ra,40(sp)
ffffffffc0200374:	6145                	addi	sp,sp,48
    cprintf("DTB init completed\n");
ffffffffc0200376:	bbc9                	j	ffffffffc0200148 <cprintf>
}
ffffffffc0200378:	7402                	ld	s0,32(sp)
ffffffffc020037a:	70a2                	ld	ra,40(sp)
        cprintf("Error: Invalid DTB magic number: 0x%x\n", magic);
ffffffffc020037c:	00001517          	auipc	a0,0x1
ffffffffc0200380:	e6c50513          	addi	a0,a0,-404 # ffffffffc02011e8 <etext+0x154>
}
ffffffffc0200384:	6145                	addi	sp,sp,48
        cprintf("Error: Invalid DTB magic number: 0x%x\n", magic);
ffffffffc0200386:	b3c9                	j	ffffffffc0200148 <cprintf>
                uint32_t prop_len = fdt32_to_cpu(*struct_ptr++);
ffffffffc0200388:	4058                	lw	a4,4(s0)
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc020038a:	0087579b          	srliw	a5,a4,0x8
ffffffffc020038e:	0187169b          	slliw	a3,a4,0x18
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200392:	0187561b          	srliw	a2,a4,0x18
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200396:	0107979b          	slliw	a5,a5,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc020039a:	0107571b          	srliw	a4,a4,0x10
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc020039e:	0107f7b3          	and	a5,a5,a6
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02003a2:	8ed1                	or	a3,a3,a2
ffffffffc02003a4:	0ff77713          	zext.b	a4,a4
ffffffffc02003a8:	8fd5                	or	a5,a5,a3
ffffffffc02003aa:	0722                	slli	a4,a4,0x8
ffffffffc02003ac:	8fd9                	or	a5,a5,a4
                if (in_memory_node && strcmp(prop_name, "reg") == 0 && prop_len >= 16) {
ffffffffc02003ae:	04031463          	bnez	t1,ffffffffc02003f6 <dtb_init+0x1ce>
                struct_ptr = (const uint32_t *)(((uintptr_t)struct_ptr + prop_len + 3) & ~3);
ffffffffc02003b2:	1782                	slli	a5,a5,0x20
ffffffffc02003b4:	9381                	srli	a5,a5,0x20
ffffffffc02003b6:	043d                	addi	s0,s0,15
ffffffffc02003b8:	943e                	add	s0,s0,a5
ffffffffc02003ba:	9871                	andi	s0,s0,-4
                break;
ffffffffc02003bc:	bfa1                	j	ffffffffc0200314 <dtb_init+0xec>
                int name_len = strlen(name);
ffffffffc02003be:	8522                	mv	a0,s0
ffffffffc02003c0:	e01a                	sd	t1,0(sp)
ffffffffc02003c2:	431000ef          	jal	ffffffffc0200ff2 <strlen>
ffffffffc02003c6:	84aa                	mv	s1,a0
                if (strncmp(name, "memory", 6) == 0) {
ffffffffc02003c8:	4619                	li	a2,6
ffffffffc02003ca:	8522                	mv	a0,s0
ffffffffc02003cc:	00001597          	auipc	a1,0x1
ffffffffc02003d0:	e4458593          	addi	a1,a1,-444 # ffffffffc0201210 <etext+0x17c>
ffffffffc02003d4:	487000ef          	jal	ffffffffc020105a <strncmp>
ffffffffc02003d8:	6302                	ld	t1,0(sp)
                struct_ptr = (const uint32_t *)(((uintptr_t)struct_ptr + name_len + 4) & ~3);
ffffffffc02003da:	0411                	addi	s0,s0,4
ffffffffc02003dc:	0004879b          	sext.w	a5,s1
ffffffffc02003e0:	943e                	add	s0,s0,a5
                if (strncmp(name, "memory", 6) == 0) {
ffffffffc02003e2:	00153513          	seqz	a0,a0
                struct_ptr = (const uint32_t *)(((uintptr_t)struct_ptr + name_len + 4) & ~3);
ffffffffc02003e6:	9871                	andi	s0,s0,-4
                if (strncmp(name, "memory", 6) == 0) {
ffffffffc02003e8:	00a36333          	or	t1,t1,a0
                break;
ffffffffc02003ec:	00ff0837          	lui	a6,0xff0
ffffffffc02003f0:	488d                	li	a7,3
ffffffffc02003f2:	4e05                	li	t3,1
ffffffffc02003f4:	b705                	j	ffffffffc0200314 <dtb_init+0xec>
                uint32_t prop_nameoff = fdt32_to_cpu(*struct_ptr++);
ffffffffc02003f6:	4418                	lw	a4,8(s0)
                if (in_memory_node && strcmp(prop_name, "reg") == 0 && prop_len >= 16) {
ffffffffc02003f8:	00001597          	auipc	a1,0x1
ffffffffc02003fc:	e2058593          	addi	a1,a1,-480 # ffffffffc0201218 <etext+0x184>
ffffffffc0200400:	e43e                	sd	a5,8(sp)
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200402:	0087551b          	srliw	a0,a4,0x8
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200406:	0187561b          	srliw	a2,a4,0x18
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc020040a:	0187169b          	slliw	a3,a4,0x18
ffffffffc020040e:	0105151b          	slliw	a0,a0,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200412:	0107571b          	srliw	a4,a4,0x10
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200416:	01057533          	and	a0,a0,a6
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc020041a:	8ed1                	or	a3,a3,a2
ffffffffc020041c:	0ff77713          	zext.b	a4,a4
ffffffffc0200420:	0722                	slli	a4,a4,0x8
ffffffffc0200422:	8d55                	or	a0,a0,a3
ffffffffc0200424:	8d59                	or	a0,a0,a4
                const char *prop_name = strings_base + prop_nameoff;
ffffffffc0200426:	1502                	slli	a0,a0,0x20
ffffffffc0200428:	9101                	srli	a0,a0,0x20
                if (in_memory_node && strcmp(prop_name, "reg") == 0 && prop_len >= 16) {
ffffffffc020042a:	954a                	add	a0,a0,s2
ffffffffc020042c:	e01a                	sd	t1,0(sp)
ffffffffc020042e:	3f9000ef          	jal	ffffffffc0201026 <strcmp>
ffffffffc0200432:	67a2                	ld	a5,8(sp)
ffffffffc0200434:	473d                	li	a4,15
ffffffffc0200436:	6302                	ld	t1,0(sp)
ffffffffc0200438:	00ff0837          	lui	a6,0xff0
ffffffffc020043c:	488d                	li	a7,3
ffffffffc020043e:	4e05                	li	t3,1
ffffffffc0200440:	f6f779e3          	bgeu	a4,a5,ffffffffc02003b2 <dtb_init+0x18a>
ffffffffc0200444:	f53d                	bnez	a0,ffffffffc02003b2 <dtb_init+0x18a>
                    *mem_base = fdt64_to_cpu(reg_data[0]);
ffffffffc0200446:	00c43683          	ld	a3,12(s0)
                    *mem_size = fdt64_to_cpu(reg_data[1]);
ffffffffc020044a:	01443703          	ld	a4,20(s0)
        cprintf("Physical Memory from DTB:\n");
ffffffffc020044e:	00001517          	auipc	a0,0x1
ffffffffc0200452:	dd250513          	addi	a0,a0,-558 # ffffffffc0201220 <etext+0x18c>
           fdt32_to_cpu(x >> 32);
ffffffffc0200456:	4206d793          	srai	a5,a3,0x20
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc020045a:	0087d31b          	srliw	t1,a5,0x8
ffffffffc020045e:	00871f93          	slli	t6,a4,0x8
           fdt32_to_cpu(x >> 32);
ffffffffc0200462:	42075893          	srai	a7,a4,0x20
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200466:	0187df1b          	srliw	t5,a5,0x18
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc020046a:	0187959b          	slliw	a1,a5,0x18
ffffffffc020046e:	0103131b          	slliw	t1,t1,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200472:	0107d79b          	srliw	a5,a5,0x10
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200476:	420fd613          	srai	a2,t6,0x20
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc020047a:	0188de9b          	srliw	t4,a7,0x18
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc020047e:	01037333          	and	t1,t1,a6
ffffffffc0200482:	01889e1b          	slliw	t3,a7,0x18
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc0200486:	01e5e5b3          	or	a1,a1,t5
ffffffffc020048a:	0ff7f793          	zext.b	a5,a5
ffffffffc020048e:	01de6e33          	or	t3,t3,t4
ffffffffc0200492:	0065e5b3          	or	a1,a1,t1
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc0200496:	01067633          	and	a2,a2,a6
ffffffffc020049a:	0086d31b          	srliw	t1,a3,0x8
ffffffffc020049e:	0087541b          	srliw	s0,a4,0x8
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02004a2:	07a2                	slli	a5,a5,0x8
ffffffffc02004a4:	0108d89b          	srliw	a7,a7,0x10
ffffffffc02004a8:	0186df1b          	srliw	t5,a3,0x18
ffffffffc02004ac:	01875e9b          	srliw	t4,a4,0x18
ffffffffc02004b0:	8ddd                	or	a1,a1,a5
ffffffffc02004b2:	01c66633          	or	a2,a2,t3
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02004b6:	0186979b          	slliw	a5,a3,0x18
ffffffffc02004ba:	01871e1b          	slliw	t3,a4,0x18
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02004be:	0ff8f893          	zext.b	a7,a7
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02004c2:	0103131b          	slliw	t1,t1,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02004c6:	0106d69b          	srliw	a3,a3,0x10
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02004ca:	0104141b          	slliw	s0,s0,0x10
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02004ce:	0107571b          	srliw	a4,a4,0x10
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02004d2:	01037333          	and	t1,t1,a6
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02004d6:	08a2                	slli	a7,a7,0x8
ffffffffc02004d8:	01e7e7b3          	or	a5,a5,t5
    return ((x & 0xff) << 24) | (((x >> 8) & 0xff) << 16) | 
ffffffffc02004dc:	01047433          	and	s0,s0,a6
           (((x >> 16) & 0xff) << 8) | ((x >> 24) & 0xff);
ffffffffc02004e0:	0ff6f693          	zext.b	a3,a3
ffffffffc02004e4:	01de6833          	or	a6,t3,t4
ffffffffc02004e8:	0ff77713          	zext.b	a4,a4
ffffffffc02004ec:	01166633          	or	a2,a2,a7
ffffffffc02004f0:	0067e7b3          	or	a5,a5,t1
ffffffffc02004f4:	06a2                	slli	a3,a3,0x8
ffffffffc02004f6:	01046433          	or	s0,s0,a6
ffffffffc02004fa:	0722                	slli	a4,a4,0x8
ffffffffc02004fc:	8fd5                	or	a5,a5,a3
ffffffffc02004fe:	8c59                	or	s0,s0,a4
           fdt32_to_cpu(x >> 32);
ffffffffc0200500:	1582                	slli	a1,a1,0x20
ffffffffc0200502:	1602                	slli	a2,a2,0x20
    return ((uint64_t)fdt32_to_cpu(x & 0xffffffff) << 32) | 
ffffffffc0200504:	1782                	slli	a5,a5,0x20
           fdt32_to_cpu(x >> 32);
ffffffffc0200506:	9201                	srli	a2,a2,0x20
ffffffffc0200508:	9181                	srli	a1,a1,0x20
    return ((uint64_t)fdt32_to_cpu(x & 0xffffffff) << 32) | 
ffffffffc020050a:	1402                	slli	s0,s0,0x20
ffffffffc020050c:	00b7e4b3          	or	s1,a5,a1
ffffffffc0200510:	8c51                	or	s0,s0,a2
        cprintf("Physical Memory from DTB:\n");
ffffffffc0200512:	c37ff0ef          	jal	ffffffffc0200148 <cprintf>
        cprintf("  Base: 0x%016lx\n", mem_base);
ffffffffc0200516:	85a6                	mv	a1,s1
ffffffffc0200518:	00001517          	auipc	a0,0x1
ffffffffc020051c:	d2850513          	addi	a0,a0,-728 # ffffffffc0201240 <etext+0x1ac>
ffffffffc0200520:	c29ff0ef          	jal	ffffffffc0200148 <cprintf>
        cprintf("  Size: 0x%016lx (%ld MB)\n", mem_size, mem_size / (1024 * 1024));
ffffffffc0200524:	01445613          	srli	a2,s0,0x14
ffffffffc0200528:	85a2                	mv	a1,s0
ffffffffc020052a:	00001517          	auipc	a0,0x1
ffffffffc020052e:	d2e50513          	addi	a0,a0,-722 # ffffffffc0201258 <etext+0x1c4>
ffffffffc0200532:	c17ff0ef          	jal	ffffffffc0200148 <cprintf>
        cprintf("  End:  0x%016lx\n", mem_base + mem_size - 1);
ffffffffc0200536:	009405b3          	add	a1,s0,s1
ffffffffc020053a:	15fd                	addi	a1,a1,-1
ffffffffc020053c:	00001517          	auipc	a0,0x1
ffffffffc0200540:	d3c50513          	addi	a0,a0,-708 # ffffffffc0201278 <etext+0x1e4>
ffffffffc0200544:	c05ff0ef          	jal	ffffffffc0200148 <cprintf>
        memory_base = mem_base;
ffffffffc0200548:	00005797          	auipc	a5,0x5
ffffffffc020054c:	b897bc23          	sd	s1,-1128(a5) # ffffffffc02050e0 <memory_base>
        memory_size = mem_size;
ffffffffc0200550:	00005797          	auipc	a5,0x5
ffffffffc0200554:	b887b423          	sd	s0,-1144(a5) # ffffffffc02050d8 <memory_size>
ffffffffc0200558:	b531                	j	ffffffffc0200364 <dtb_init+0x13c>

ffffffffc020055a <get_memory_base>:

uint64_t get_memory_base(void) {
    return memory_base;
}
ffffffffc020055a:	00005517          	auipc	a0,0x5
ffffffffc020055e:	b8653503          	ld	a0,-1146(a0) # ffffffffc02050e0 <memory_base>
ffffffffc0200562:	8082                	ret

ffffffffc0200564 <get_memory_size>:

uint64_t get_memory_size(void) {
    return memory_size;
ffffffffc0200564:	00005517          	auipc	a0,0x5
ffffffffc0200568:	b7453503          	ld	a0,-1164(a0) # ffffffffc02050d8 <memory_size>
ffffffffc020056c:	8082                	ret

ffffffffc020056e <buddy_nr_free_pages>:

// 检查伙伴系统状态
static size_t buddy_nr_free_pages(void) {
    size_t total_free = 0;
    
    for (int i = 0; i <= buddy_sys.max_order; i++) {
ffffffffc020056e:	00005617          	auipc	a2,0x5
ffffffffc0200572:	aae66603          	lwu	a2,-1362(a2) # ffffffffc020501c <buddy_sys+0x4>
ffffffffc0200576:	00005797          	auipc	a5,0x5
ffffffffc020057a:	aba78793          	addi	a5,a5,-1350 # ffffffffc0205030 <buddy_sys+0x18>
ffffffffc020057e:	00005697          	auipc	a3,0x5
ffffffffc0200582:	aa268693          	addi	a3,a3,-1374 # ffffffffc0205020 <buddy_sys+0x8>
ffffffffc0200586:	0612                	slli	a2,a2,0x4
ffffffffc0200588:	963e                	add	a2,a2,a5
    size_t total_free = 0;
ffffffffc020058a:	4501                	li	a0,0
 * list_next - get the next entry
 * @listelm:    the list head
 **/
static inline list_entry_t *
list_next(list_entry_t *listelm) {
    return listelm->next;
ffffffffc020058c:	669c                	ld	a5,8(a3)
        list_entry_t *le = &buddy_sys.free_list[i];
        list_entry_t *list_head = le;
        le = list_next(le);
        
        while (le != list_head) {
ffffffffc020058e:	00f68863          	beq	a3,a5,ffffffffc020059e <buddy_nr_free_pages+0x30>
            struct Page *page = le2page(le, page_link);
            total_free += page->property;
ffffffffc0200592:	ff87e703          	lwu	a4,-8(a5)
ffffffffc0200596:	679c                	ld	a5,8(a5)
ffffffffc0200598:	953a                	add	a0,a0,a4
        while (le != list_head) {
ffffffffc020059a:	fed79ce3          	bne	a5,a3,ffffffffc0200592 <buddy_nr_free_pages+0x24>
    for (int i = 0; i <= buddy_sys.max_order; i++) {
ffffffffc020059e:	06c1                	addi	a3,a3,16
ffffffffc02005a0:	fec696e3          	bne	a3,a2,ffffffffc020058c <buddy_nr_free_pages+0x1e>
            le = list_next(le);
        }
    }
    
    return total_free;
}
ffffffffc02005a4:	8082                	ret

ffffffffc02005a6 <buddy_init>:
static void buddy_init(void) {
ffffffffc02005a6:	1141                	addi	sp,sp,-16
    cprintf("buddy_init: starting\n");
ffffffffc02005a8:	00001517          	auipc	a0,0x1
ffffffffc02005ac:	d3850513          	addi	a0,a0,-712 # ffffffffc02012e0 <etext+0x24c>
static void buddy_init(void) {
ffffffffc02005b0:	e406                	sd	ra,8(sp)
    cprintf("buddy_init: starting\n");
ffffffffc02005b2:	b97ff0ef          	jal	ffffffffc0200148 <cprintf>
    for (int i = 0; i <= MAX_ORDER; i++) {
ffffffffc02005b6:	00005797          	auipc	a5,0x5
ffffffffc02005ba:	a6a78793          	addi	a5,a5,-1430 # ffffffffc0205020 <buddy_sys+0x8>
ffffffffc02005be:	00005717          	auipc	a4,0x5
ffffffffc02005c2:	b1270713          	addi	a4,a4,-1262 # ffffffffc02050d0 <is_panic>
    elm->prev = elm->next = elm;
ffffffffc02005c6:	e79c                	sd	a5,8(a5)
ffffffffc02005c8:	e39c                	sd	a5,0(a5)
ffffffffc02005ca:	07c1                	addi	a5,a5,16
ffffffffc02005cc:	fee79de3          	bne	a5,a4,ffffffffc02005c6 <buddy_init+0x20>
}
ffffffffc02005d0:	60a2                	ld	ra,8(sp)
    buddy_sys.size = 0;
ffffffffc02005d2:	00005797          	auipc	a5,0x5
ffffffffc02005d6:	a407b323          	sd	zero,-1466(a5) # ffffffffc0205018 <buddy_sys>
    cprintf("buddy_init: completed\n");
ffffffffc02005da:	00001517          	auipc	a0,0x1
ffffffffc02005de:	d1e50513          	addi	a0,a0,-738 # ffffffffc02012f8 <etext+0x264>
}
ffffffffc02005e2:	0141                	addi	sp,sp,16
    cprintf("buddy_init: completed\n");
ffffffffc02005e4:	b695                	j	ffffffffc0200148 <cprintf>

ffffffffc02005e6 <buddy_alloc_pages>:
    if (n == 0 || n > buddy_sys.size) {
ffffffffc02005e6:	cd75                	beqz	a0,ffffffffc02006e2 <buddy_alloc_pages+0xfc>
ffffffffc02005e8:	00005797          	auipc	a5,0x5
ffffffffc02005ec:	a307e783          	lwu	a5,-1488(a5) # ffffffffc0205018 <buddy_sys>
ffffffffc02005f0:	0ea7e863          	bltu	a5,a0,ffffffffc02006e0 <buddy_alloc_pages+0xfa>
    unsigned int alloc_size = round_up_power_of_2(n);
ffffffffc02005f4:	00050e9b          	sext.w	t4,a0
    return n != 0 && (n & (n - 1)) == 0;
ffffffffc02005f8:	357d                	addiw	a0,a0,-1
ffffffffc02005fa:	00aef7b3          	and	a5,t4,a0
ffffffffc02005fe:	e3fd                	bnez	a5,ffffffffc02006e4 <buddy_alloc_pages+0xfe>
    while (temp > 1) {
ffffffffc0200600:	4705                	li	a4,1
    while (current_order <= buddy_sys.max_order) {
ffffffffc0200602:	00005517          	auipc	a0,0x5
ffffffffc0200606:	a1a52503          	lw	a0,-1510(a0) # ffffffffc020501c <buddy_sys+0x4>
    while (temp > 1) {
ffffffffc020060a:	0eee8f63          	beq	t4,a4,ffffffffc0200708 <buddy_alloc_pages+0x122>
    unsigned int temp = n;
ffffffffc020060e:	87f6                	mv	a5,t4
    unsigned int order = 0;
ffffffffc0200610:	4581                	li	a1,0
        temp >>= 1;
ffffffffc0200612:	0017d79b          	srliw	a5,a5,0x1
        order++;
ffffffffc0200616:	2585                	addiw	a1,a1,1
    while (temp > 1) {
ffffffffc0200618:	fee79de3          	bne	a5,a4,ffffffffc0200612 <buddy_alloc_pages+0x2c>
    while (current_order <= buddy_sys.max_order) {
ffffffffc020061c:	0cb56263          	bltu	a0,a1,ffffffffc02006e0 <buddy_alloc_pages+0xfa>
    unsigned int current_order = order;
ffffffffc0200620:	87ae                	mv	a5,a1
ffffffffc0200622:	00005697          	auipc	a3,0x5
ffffffffc0200626:	9f668693          	addi	a3,a3,-1546 # ffffffffc0205018 <buddy_sys>
ffffffffc020062a:	a021                	j	ffffffffc0200632 <buddy_alloc_pages+0x4c>
        current_order++;
ffffffffc020062c:	2785                	addiw	a5,a5,1
    while (current_order <= buddy_sys.max_order) {
ffffffffc020062e:	0af56963          	bltu	a0,a5,ffffffffc02006e0 <buddy_alloc_pages+0xfa>
        if (!list_empty(&buddy_sys.free_list[current_order])) {
ffffffffc0200632:	02079613          	slli	a2,a5,0x20
ffffffffc0200636:	01c65713          	srli	a4,a2,0x1c
    return list->next == list;
ffffffffc020063a:	00e68633          	add	a2,a3,a4
ffffffffc020063e:	6a10                	ld	a2,16(a2)
ffffffffc0200640:	0721                	addi	a4,a4,8
ffffffffc0200642:	9736                	add	a4,a4,a3
ffffffffc0200644:	fee604e3          	beq	a2,a4,ffffffffc020062c <buddy_alloc_pages+0x46>
    if (current_order > buddy_sys.max_order) {
ffffffffc0200648:	08f56c63          	bltu	a0,a5,ffffffffc02006e0 <buddy_alloc_pages+0xfa>
    __list_del(listelm->prev, listelm->next);
ffffffffc020064c:	6214                	ld	a3,0(a2)
ffffffffc020064e:	6618                	ld	a4,8(a2)
    struct Page *page = le2page(le, page_link);
ffffffffc0200650:	fe860513          	addi	a0,a2,-24
 * This is only for internal list manipulation where we know
 * the prev/next entries already!
 * */
static inline void
__list_del(list_entry_t *prev, list_entry_t *next) {
    prev->next = next;
ffffffffc0200654:	e698                	sd	a4,8(a3)
    next->prev = prev;
ffffffffc0200656:	e314                	sd	a3,0(a4)
    while (current_order > order) {
ffffffffc0200658:	04f5fb63          	bgeu	a1,a5,ffffffffc02006ae <buddy_alloc_pages+0xc8>
ffffffffc020065c:	fff7871b          	addiw	a4,a5,-1
ffffffffc0200660:	02071793          	slli	a5,a4,0x20
ffffffffc0200664:	01c7d693          	srli	a3,a5,0x1c
ffffffffc0200668:	00005797          	auipc	a5,0x5
ffffffffc020066c:	9b878793          	addi	a5,a5,-1608 # ffffffffc0205020 <buddy_sys+0x8>
ffffffffc0200670:	96be                	add	a3,a3,a5
        unsigned int split_size = 1 << current_order;
ffffffffc0200672:	4e05                	li	t3,1
ffffffffc0200674:	a011                	j	ffffffffc0200678 <buddy_alloc_pages+0x92>
ffffffffc0200676:	377d                	addiw	a4,a4,-1
ffffffffc0200678:	00ee18bb          	sllw	a7,t3,a4
        struct Page *buddy = page + split_size;
ffffffffc020067c:	02089313          	slli	t1,a7,0x20
ffffffffc0200680:	02035313          	srli	t1,t1,0x20
ffffffffc0200684:	00231793          	slli	a5,t1,0x2
ffffffffc0200688:	979a                	add	a5,a5,t1
    __list_add(elm, listelm, listelm->next);
ffffffffc020068a:	0086b803          	ld	a6,8(a3)
ffffffffc020068e:	078e                	slli	a5,a5,0x3
ffffffffc0200690:	97aa                	add	a5,a5,a0
        buddy->property = split_size;
ffffffffc0200692:	0117a823          	sw	a7,16(a5)
        list_add(&buddy_sys.free_list[current_order], &(buddy->page_link));
ffffffffc0200696:	01878893          	addi	a7,a5,24
    prev->next = next->prev = elm;
ffffffffc020069a:	01183023          	sd	a7,0(a6) # ff0000 <kern_entry-0xffffffffbf210000>
ffffffffc020069e:	0116b423          	sd	a7,8(a3)
    elm->prev = prev;
ffffffffc02006a2:	ef94                	sd	a3,24(a5)
    elm->next = next;
ffffffffc02006a4:	0307b023          	sd	a6,32(a5)
    while (current_order > order) {
ffffffffc02006a8:	16c1                	addi	a3,a3,-16
ffffffffc02006aa:	fcb716e3          	bne	a4,a1,ffffffffc0200676 <buddy_alloc_pages+0x90>
    ClearPageProperty(page); // 标记为已分配
ffffffffc02006ae:	ff063783          	ld	a5,-16(a2)
    for (struct Page *p = page; p != page + alloc_size; p++) {
ffffffffc02006b2:	020e9713          	slli	a4,t4,0x20
ffffffffc02006b6:	9301                	srli	a4,a4,0x20
ffffffffc02006b8:	00271693          	slli	a3,a4,0x2
ffffffffc02006bc:	96ba                	add	a3,a3,a4
    ClearPageProperty(page); // 标记为已分配
ffffffffc02006be:	9bf5                	andi	a5,a5,-3
    for (struct Page *p = page; p != page + alloc_size; p++) {
ffffffffc02006c0:	068e                	slli	a3,a3,0x3
    ClearPageProperty(page); // 标记为已分配
ffffffffc02006c2:	fef63823          	sd	a5,-16(a2)
    page->property = alloc_size;
ffffffffc02006c6:	ffd62c23          	sw	t4,-8(a2)
    for (struct Page *p = page; p != page + alloc_size; p++) {
ffffffffc02006ca:	00d50733          	add	a4,a0,a3
ffffffffc02006ce:	87aa                	mv	a5,a0
ffffffffc02006d0:	ca9d                	beqz	a3,ffffffffc0200706 <buddy_alloc_pages+0x120>



static inline int page_ref(struct Page *page) { return page->ref; }

static inline void set_page_ref(struct Page *page, int val) { page->ref = val; }
ffffffffc02006d2:	0007a023          	sw	zero,0(a5)
ffffffffc02006d6:	02878793          	addi	a5,a5,40
ffffffffc02006da:	fee79ce3          	bne	a5,a4,ffffffffc02006d2 <buddy_alloc_pages+0xec>
ffffffffc02006de:	8082                	ret
        return NULL;
ffffffffc02006e0:	4501                	li	a0,0
}
ffffffffc02006e2:	8082                	ret
    unsigned int order = 0;
ffffffffc02006e4:	4781                	li	a5,0
        temp >>= 1;
ffffffffc02006e6:	0015551b          	srliw	a0,a0,0x1
        order++;
ffffffffc02006ea:	2785                	addiw	a5,a5,1
    while (temp > 0) {
ffffffffc02006ec:	fd6d                	bnez	a0,ffffffffc02006e6 <buddy_alloc_pages+0x100>
    return 1 << order;
ffffffffc02006ee:	4585                	li	a1,1
ffffffffc02006f0:	00f595bb          	sllw	a1,a1,a5
    if (n == 0) return 0;
ffffffffc02006f4:	e599                	bnez	a1,ffffffffc0200702 <buddy_alloc_pages+0x11c>
    while (current_order <= buddy_sys.max_order) {
ffffffffc02006f6:	00005517          	auipc	a0,0x5
ffffffffc02006fa:	92652503          	lw	a0,-1754(a0) # ffffffffc020501c <buddy_sys+0x4>
ffffffffc02006fe:	4e81                	li	t4,0
ffffffffc0200700:	b705                	j	ffffffffc0200620 <buddy_alloc_pages+0x3a>
ffffffffc0200702:	8eae                	mv	t4,a1
ffffffffc0200704:	bdf5                	j	ffffffffc0200600 <buddy_alloc_pages+0x1a>
ffffffffc0200706:	8082                	ret
    unsigned int order = 0;
ffffffffc0200708:	4581                	li	a1,0
ffffffffc020070a:	bf19                	j	ffffffffc0200620 <buddy_alloc_pages+0x3a>

ffffffffc020070c <buddy_init_memmap>:
static void buddy_init_memmap(struct Page *base, size_t n) {
ffffffffc020070c:	1101                	addi	sp,sp,-32
ffffffffc020070e:	ec06                	sd	ra,24(sp)
ffffffffc0200710:	e822                	sd	s0,16(sp)
    assert(n > 0);
ffffffffc0200712:	c1e1                	beqz	a1,ffffffffc02007d2 <buddy_init_memmap+0xc6>
ffffffffc0200714:	862e                	mv	a2,a1
    cprintf("buddy_init_memmap: base=%p, n=%lu\n", base, n);
ffffffffc0200716:	e42e                	sd	a1,8(sp)
ffffffffc0200718:	842a                	mv	s0,a0
ffffffffc020071a:	85aa                	mv	a1,a0
ffffffffc020071c:	00001517          	auipc	a0,0x1
ffffffffc0200720:	c2c50513          	addi	a0,a0,-980 # ffffffffc0201348 <etext+0x2b4>
ffffffffc0200724:	a25ff0ef          	jal	ffffffffc0200148 <cprintf>
    size_t init_count = (n < 64) ? n : 64;
ffffffffc0200728:	6622                	ld	a2,8(sp)
ffffffffc020072a:	04000793          	li	a5,64
ffffffffc020072e:	08c7e063          	bltu	a5,a2,ffffffffc02007ae <buddy_init_memmap+0xa2>
    for (struct Page *p = base; p != base + init_count; p++) {
ffffffffc0200732:	00261693          	slli	a3,a2,0x2
ffffffffc0200736:	96b2                	add	a3,a3,a2
ffffffffc0200738:	068e                	slli	a3,a3,0x3
ffffffffc020073a:	96a2                	add	a3,a3,s0
ffffffffc020073c:	87a2                	mv	a5,s0
        SetPageProperty(p);
ffffffffc020073e:	4609                	li	a2,2
        assert(PageReserved(p));
ffffffffc0200740:	6798                	ld	a4,8(a5)
ffffffffc0200742:	8b05                	andi	a4,a4,1
ffffffffc0200744:	c73d                	beqz	a4,ffffffffc02007b2 <buddy_init_memmap+0xa6>
        p->property = 0;
ffffffffc0200746:	0007a823          	sw	zero,16(a5)
ffffffffc020074a:	0007a023          	sw	zero,0(a5)
        SetPageProperty(p);
ffffffffc020074e:	e790                	sd	a2,8(a5)
    for (struct Page *p = base; p != base + init_count; p++) {
ffffffffc0200750:	02878793          	addi	a5,a5,40
ffffffffc0200754:	fed796e3          	bne	a5,a3,ffffffffc0200740 <buddy_init_memmap+0x34>
    buddy_sys.size = total_pages;
ffffffffc0200758:	478d                	li	a5,3
    __list_add(elm, listelm, listelm->next);
ffffffffc020075a:	00005717          	auipc	a4,0x5
ffffffffc020075e:	92e73703          	ld	a4,-1746(a4) # ffffffffc0205088 <buddy_sys+0x70>
ffffffffc0200762:	1786                	slli	a5,a5,0x21
ffffffffc0200764:	04078793          	addi	a5,a5,64
    base->property = total_pages;
ffffffffc0200768:	04000593          	li	a1,64
ffffffffc020076c:	c80c                	sw	a1,16(s0)
    buddy_sys.size = total_pages;
ffffffffc020076e:	00005697          	auipc	a3,0x5
ffffffffc0200772:	8af6b523          	sd	a5,-1878(a3) # ffffffffc0205018 <buddy_sys>
    list_add(&buddy_sys.free_list[buddy_sys.max_order], &(base->page_link));
ffffffffc0200776:	01840793          	addi	a5,s0,24
    prev->next = next->prev = elm;
ffffffffc020077a:	e31c                	sd	a5,0(a4)
ffffffffc020077c:	00005697          	auipc	a3,0x5
ffffffffc0200780:	90f6b623          	sd	a5,-1780(a3) # ffffffffc0205088 <buddy_sys+0x70>
    elm->prev = prev;
ffffffffc0200784:	00005797          	auipc	a5,0x5
ffffffffc0200788:	8fc78793          	addi	a5,a5,-1796 # ffffffffc0205080 <buddy_sys+0x68>
    elm->next = next;
ffffffffc020078c:	f018                	sd	a4,32(s0)
    elm->prev = prev;
ffffffffc020078e:	ec1c                	sd	a5,24(s0)
    cprintf("buddy system init: total_pages = %u, max_order = %u\n", 
ffffffffc0200790:	4619                	li	a2,6
ffffffffc0200792:	00001517          	auipc	a0,0x1
ffffffffc0200796:	bee50513          	addi	a0,a0,-1042 # ffffffffc0201380 <etext+0x2ec>
ffffffffc020079a:	9afff0ef          	jal	ffffffffc0200148 <cprintf>
}
ffffffffc020079e:	6442                	ld	s0,16(sp)
ffffffffc02007a0:	60e2                	ld	ra,24(sp)
    cprintf("buddy_init_memmap: completed successfully\n");
ffffffffc02007a2:	00001517          	auipc	a0,0x1
ffffffffc02007a6:	c1650513          	addi	a0,a0,-1002 # ffffffffc02013b8 <etext+0x324>
}
ffffffffc02007aa:	6105                	addi	sp,sp,32
    cprintf("buddy_init_memmap: completed successfully\n");
ffffffffc02007ac:	ba71                	j	ffffffffc0200148 <cprintf>
    size_t init_count = (n < 64) ? n : 64;
ffffffffc02007ae:	863e                	mv	a2,a5
ffffffffc02007b0:	b749                	j	ffffffffc0200732 <buddy_init_memmap+0x26>
        assert(PageReserved(p));
ffffffffc02007b2:	00001697          	auipc	a3,0x1
ffffffffc02007b6:	bbe68693          	addi	a3,a3,-1090 # ffffffffc0201370 <etext+0x2dc>
ffffffffc02007ba:	00001617          	auipc	a2,0x1
ffffffffc02007be:	b5e60613          	addi	a2,a2,-1186 # ffffffffc0201318 <etext+0x284>
ffffffffc02007c2:	04700593          	li	a1,71
ffffffffc02007c6:	00001517          	auipc	a0,0x1
ffffffffc02007ca:	b6a50513          	addi	a0,a0,-1174 # ffffffffc0201330 <etext+0x29c>
ffffffffc02007ce:	9fbff0ef          	jal	ffffffffc02001c8 <__panic>
    assert(n > 0);
ffffffffc02007d2:	00001697          	auipc	a3,0x1
ffffffffc02007d6:	b3e68693          	addi	a3,a3,-1218 # ffffffffc0201310 <etext+0x27c>
ffffffffc02007da:	00001617          	auipc	a2,0x1
ffffffffc02007de:	b3e60613          	addi	a2,a2,-1218 # ffffffffc0201318 <etext+0x284>
ffffffffc02007e2:	04100593          	li	a1,65
ffffffffc02007e6:	00001517          	auipc	a0,0x1
ffffffffc02007ea:	b4a50513          	addi	a0,a0,-1206 # ffffffffc0201330 <etext+0x29c>
ffffffffc02007ee:	9dbff0ef          	jal	ffffffffc02001c8 <__panic>

ffffffffc02007f2 <buddy_free_pages>:
    if (n == 0) {
ffffffffc02007f2:	12058863          	beqz	a1,ffffffffc0200922 <buddy_free_pages+0x130>
    unsigned int free_size = base->property;
ffffffffc02007f6:	4910                	lw	a2,16(a0)
    for (struct Page *p = base; p != base + free_size; p++) {
ffffffffc02007f8:	87aa                	mv	a5,a0
ffffffffc02007fa:	02061693          	slli	a3,a2,0x20
ffffffffc02007fe:	9281                	srli	a3,a3,0x20
ffffffffc0200800:	00269713          	slli	a4,a3,0x2
ffffffffc0200804:	9736                	add	a4,a4,a3
ffffffffc0200806:	070e                	slli	a4,a4,0x3
ffffffffc0200808:	00e505b3          	add	a1,a0,a4
ffffffffc020080c:	cf19                	beqz	a4,ffffffffc020082a <buddy_free_pages+0x38>
        assert(!PageReserved(p));
ffffffffc020080e:	6798                	ld	a4,8(a5)
ffffffffc0200810:	00177693          	andi	a3,a4,1
ffffffffc0200814:	12069763          	bnez	a3,ffffffffc0200942 <buddy_free_pages+0x150>
        SetPageProperty(p);
ffffffffc0200818:	00276713          	ori	a4,a4,2
ffffffffc020081c:	e798                	sd	a4,8(a5)
ffffffffc020081e:	0007a023          	sw	zero,0(a5)
    for (struct Page *p = base; p != base + free_size; p++) {
ffffffffc0200822:	02878793          	addi	a5,a5,40
ffffffffc0200826:	feb794e3          	bne	a5,a1,ffffffffc020080e <buddy_free_pages+0x1c>
    if (n == 0) return 0;
ffffffffc020082a:	4805                	li	a6,1
    unsigned int order = 0;
ffffffffc020082c:	4701                	li	a4,0
    if (n == 0) return 0;
ffffffffc020082e:	0ec87b63          	bgeu	a6,a2,ffffffffc0200924 <buddy_free_pages+0x132>
        temp >>= 1;
ffffffffc0200832:	0016561b          	srliw	a2,a2,0x1
        order++;
ffffffffc0200836:	2705                	addiw	a4,a4,1
    while (temp > 1) {
ffffffffc0200838:	ff061de3          	bne	a2,a6,ffffffffc0200832 <buddy_free_pages+0x40>
ffffffffc020083c:	02071793          	slli	a5,a4,0x20
ffffffffc0200840:	01c7d893          	srli	a7,a5,0x1c
    current_block->property = 1 << current_order;
ffffffffc0200844:	00e6183b          	sllw	a6,a2,a4
ffffffffc0200848:	08a1                	addi	a7,a7,8
    while (current_order < buddy_sys.max_order) {
ffffffffc020084a:	00004f17          	auipc	t5,0x4
ffffffffc020084e:	7d2f2f03          	lw	t5,2002(t5) # ffffffffc020501c <buddy_sys+0x4>
ffffffffc0200852:	00004e97          	auipc	t4,0x4
ffffffffc0200856:	7c6e8e93          	addi	t4,t4,1990 # ffffffffc0205018 <buddy_sys>
ffffffffc020085a:	0de77b63          	bgeu	a4,t5,ffffffffc0200930 <buddy_free_pages+0x13e>
    if (buddy < (struct Page *)0 || buddy >= (struct Page *)0 + buddy_sys.size) {
ffffffffc020085e:	00004697          	auipc	a3,0x4
ffffffffc0200862:	7ba6e683          	lwu	a3,1978(a3) # ffffffffc0205018 <buddy_sys>
        unsigned long block_index = (current_block - (struct Page *)0);
ffffffffc0200866:	ccccd7b7          	lui	a5,0xccccd
ffffffffc020086a:	ccd78793          	addi	a5,a5,-819 # ffffffffcccccccd <end+0xcac7bb5>
ffffffffc020086e:	02079293          	slli	t0,a5,0x20
    if (buddy < (struct Page *)0 || buddy >= (struct Page *)0 + buddy_sys.size) {
ffffffffc0200872:	00269313          	slli	t1,a3,0x2
        unsigned long block_index = (current_block - (struct Page *)0);
ffffffffc0200876:	92be                	add	t0,t0,a5
ffffffffc0200878:	02071793          	slli	a5,a4,0x20
ffffffffc020087c:	01c7d613          	srli	a2,a5,0x1c
    if (buddy < (struct Page *)0 || buddy >= (struct Page *)0 + buddy_sys.size) {
ffffffffc0200880:	9336                	add	t1,t1,a3
ffffffffc0200882:	00004797          	auipc	a5,0x4
ffffffffc0200886:	79e78793          	addi	a5,a5,1950 # ffffffffc0205020 <buddy_sys+0x8>
ffffffffc020088a:	030e                	slli	t1,t1,0x3
ffffffffc020088c:	963e                	add	a2,a2,a5
        unsigned long buddy_index = block_index ^ (1 << current_order);
ffffffffc020088e:	4e05                	li	t3,1
        unsigned long block_index = (current_block - (struct Page *)0);
ffffffffc0200890:	40355693          	srai	a3,a0,0x3
ffffffffc0200894:	025686b3          	mul	a3,a3,t0
        unsigned long buddy_index = block_index ^ (1 << current_order);
ffffffffc0200898:	00ee17bb          	sllw	a5,t3,a4
    if (!PageProperty(buddy) || buddy->property != (1 << order)) {
ffffffffc020089c:	883e                	mv	a6,a5
    return listelm->next;
ffffffffc020089e:	00863f83          	ld	t6,8(a2)
    list_entry_t *le = &buddy_sys.free_list[order];
ffffffffc02008a2:	88b2                	mv	a7,a2
        unsigned long buddy_index = block_index ^ (1 << current_order);
ffffffffc02008a4:	8ebd                	xor	a3,a3,a5
        struct Page *buddy = (struct Page *)0 + buddy_index;
ffffffffc02008a6:	00269793          	slli	a5,a3,0x2
ffffffffc02008aa:	97b6                	add	a5,a5,a3
ffffffffc02008ac:	078e                	slli	a5,a5,0x3
    if (buddy < (struct Page *)0 || buddy >= (struct Page *)0 + buddy_sys.size) {
ffffffffc02008ae:	0667fe63          	bgeu	a5,t1,ffffffffc020092a <buddy_free_pages+0x138>
    if (!PageProperty(buddy) || buddy->property != (1 << order)) {
ffffffffc02008b2:	6794                	ld	a3,8(a5)
ffffffffc02008b4:	8a89                	andi	a3,a3,2
ffffffffc02008b6:	cab5                	beqz	a3,ffffffffc020092a <buddy_free_pages+0x138>
ffffffffc02008b8:	4b94                	lw	a3,16(a5)
ffffffffc02008ba:	07069863          	bne	a3,a6,ffffffffc020092a <buddy_free_pages+0x138>
    while (le != list_head) {
ffffffffc02008be:	07f60663          	beq	a2,t6,ffffffffc020092a <buddy_free_pages+0x138>
    le = list_next(le);
ffffffffc02008c2:	86fe                	mv	a3,t6
ffffffffc02008c4:	a021                	j	ffffffffc02008cc <buddy_free_pages+0xda>
ffffffffc02008c6:	6694                	ld	a3,8(a3)
    while (le != list_head) {
ffffffffc02008c8:	06c68163          	beq	a3,a2,ffffffffc020092a <buddy_free_pages+0x138>
        struct Page *page = le2page(le, page_link);
ffffffffc02008cc:	fe868593          	addi	a1,a3,-24
        if (page == buddy) {
ffffffffc02008d0:	fef59be3          	bne	a1,a5,ffffffffc02008c6 <buddy_free_pages+0xd4>
    __list_del(listelm->prev, listelm->next);
ffffffffc02008d4:	6f8c                	ld	a1,24(a5)
ffffffffc02008d6:	7394                	ld	a3,32(a5)
    prev->next = next;
ffffffffc02008d8:	e594                	sd	a3,8(a1)
    next->prev = prev;
ffffffffc02008da:	e28c                	sd	a1,0(a3)
        if (current_block > buddy) {
ffffffffc02008dc:	00a7f363          	bgeu	a5,a0,ffffffffc02008e2 <buddy_free_pages+0xf0>
ffffffffc02008e0:	853e                	mv	a0,a5
        current_order++;
ffffffffc02008e2:	2705                	addiw	a4,a4,1
    while (current_order < buddy_sys.max_order) {
ffffffffc02008e4:	0641                	addi	a2,a2,16
ffffffffc02008e6:	faef15e3          	bne	t5,a4,ffffffffc0200890 <buddy_free_pages+0x9e>
    list_add(&buddy_sys.free_list[current_order], &(current_block->page_link));
ffffffffc02008ea:	020f1713          	slli	a4,t5,0x20
ffffffffc02008ee:	9301                	srli	a4,a4,0x20
ffffffffc02008f0:	00471893          	slli	a7,a4,0x4
    __list_add(elm, listelm, listelm->next);
ffffffffc02008f4:	011e87b3          	add	a5,t4,a7
ffffffffc02008f8:	0107bf83          	ld	t6,16(a5)
    current_block->property = 1 << current_order;
ffffffffc02008fc:	4805                	li	a6,1
    list_add(&buddy_sys.free_list[current_order], &(current_block->page_link));
ffffffffc02008fe:	08a1                	addi	a7,a7,8
    current_block->property = 1 << current_order;
ffffffffc0200900:	01e8183b          	sllw	a6,a6,t5
    list_add(&buddy_sys.free_list[current_order], &(current_block->page_link));
ffffffffc0200904:	98f6                	add	a7,a7,t4
    current_block->property = 1 << current_order;
ffffffffc0200906:	01052823          	sw	a6,16(a0)
    list_add(&buddy_sys.free_list[current_order], &(current_block->page_link));
ffffffffc020090a:	01850793          	addi	a5,a0,24
    prev->next = next->prev = elm;
ffffffffc020090e:	0712                	slli	a4,a4,0x4
ffffffffc0200910:	00ffb023          	sd	a5,0(t6)
ffffffffc0200914:	9eba                	add	t4,t4,a4
ffffffffc0200916:	00feb823          	sd	a5,16(t4)
    elm->next = next;
ffffffffc020091a:	03f53023          	sd	t6,32(a0)
    elm->prev = prev;
ffffffffc020091e:	01153c23          	sd	a7,24(a0)
ffffffffc0200922:	8082                	ret
ffffffffc0200924:	48a1                	li	a7,8
    if (n == 0) return 0;
ffffffffc0200926:	4701                	li	a4,0
ffffffffc0200928:	b70d                	j	ffffffffc020084a <buddy_free_pages+0x58>
ffffffffc020092a:	1702                	slli	a4,a4,0x20
ffffffffc020092c:	9301                	srli	a4,a4,0x20
ffffffffc020092e:	bfe1                	j	ffffffffc0200906 <buddy_free_pages+0x114>
    __list_add(elm, listelm, listelm->next);
ffffffffc0200930:	1702                	slli	a4,a4,0x20
ffffffffc0200932:	9301                	srli	a4,a4,0x20
ffffffffc0200934:	00471793          	slli	a5,a4,0x4
ffffffffc0200938:	97f6                	add	a5,a5,t4
ffffffffc020093a:	0107bf83          	ld	t6,16(a5)
    list_add(&buddy_sys.free_list[current_order], &(current_block->page_link));
ffffffffc020093e:	98f6                	add	a7,a7,t4
ffffffffc0200940:	b7d9                	j	ffffffffc0200906 <buddy_free_pages+0x114>
static void buddy_free_pages(struct Page *base, size_t n) {
ffffffffc0200942:	1141                	addi	sp,sp,-16
        assert(!PageReserved(p));
ffffffffc0200944:	00001697          	auipc	a3,0x1
ffffffffc0200948:	aa468693          	addi	a3,a3,-1372 # ffffffffc02013e8 <etext+0x354>
ffffffffc020094c:	00001617          	auipc	a2,0x1
ffffffffc0200950:	9cc60613          	addi	a2,a2,-1588 # ffffffffc0201318 <etext+0x284>
ffffffffc0200954:	0b700593          	li	a1,183
ffffffffc0200958:	00001517          	auipc	a0,0x1
ffffffffc020095c:	9d850513          	addi	a0,a0,-1576 # ffffffffc0201330 <etext+0x29c>
static void buddy_free_pages(struct Page *base, size_t n) {
ffffffffc0200960:	e406                	sd	ra,8(sp)
        assert(!PageReserved(p));
ffffffffc0200962:	867ff0ef          	jal	ffffffffc02001c8 <__panic>

ffffffffc0200966 <buddy_check>:

// 检查伙伴系统
static void buddy_check(void) {
ffffffffc0200966:	7179                	addi	sp,sp,-48
    cprintf("=== Buddy System Check ===\n");
ffffffffc0200968:	00001517          	auipc	a0,0x1
ffffffffc020096c:	a9850513          	addi	a0,a0,-1384 # ffffffffc0201400 <etext+0x36c>
static void buddy_check(void) {
ffffffffc0200970:	f406                	sd	ra,40(sp)
ffffffffc0200972:	f022                	sd	s0,32(sp)
ffffffffc0200974:	ec26                	sd	s1,24(sp)
ffffffffc0200976:	e84a                	sd	s2,16(sp)
ffffffffc0200978:	e44e                	sd	s3,8(sp)
    cprintf("=== Buddy System Check ===\n");
ffffffffc020097a:	fceff0ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("Total managed pages: %u\n", buddy_sys.size);
ffffffffc020097e:	00004597          	auipc	a1,0x4
ffffffffc0200982:	69a5a583          	lw	a1,1690(a1) # ffffffffc0205018 <buddy_sys>
ffffffffc0200986:	00001517          	auipc	a0,0x1
ffffffffc020098a:	a9a50513          	addi	a0,a0,-1382 # ffffffffc0201420 <etext+0x38c>
ffffffffc020098e:	00004417          	auipc	s0,0x4
ffffffffc0200992:	69240413          	addi	s0,s0,1682 # ffffffffc0205020 <buddy_sys+0x8>
ffffffffc0200996:	fb2ff0ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("Max order: %u\n", buddy_sys.max_order);
ffffffffc020099a:	00004597          	auipc	a1,0x4
ffffffffc020099e:	6825a583          	lw	a1,1666(a1) # ffffffffc020501c <buddy_sys+0x4>
ffffffffc02009a2:	00001517          	auipc	a0,0x1
ffffffffc02009a6:	a9e50513          	addi	a0,a0,-1378 # ffffffffc0201440 <etext+0x3ac>
ffffffffc02009aa:	84a2                	mv	s1,s0
ffffffffc02009ac:	f9cff0ef          	jal	ffffffffc0200148 <cprintf>
    
    for (int i = 0; i <= buddy_sys.max_order; i++) {
ffffffffc02009b0:	4901                	li	s2,0
        
        while (le != list_head) {
            count++;
            le = list_next(le);
        }
        cprintf("Order %d: %d free blocks (size=%d)\n", i, count, 1 << i);
ffffffffc02009b2:	4985                	li	s3,1
    return listelm->next;
ffffffffc02009b4:	649c                	ld	a5,8(s1)
        int count = 0;
ffffffffc02009b6:	4601                	li	a2,0
        while (le != list_head) {
ffffffffc02009b8:	00978663          	beq	a5,s1,ffffffffc02009c4 <buddy_check+0x5e>
ffffffffc02009bc:	679c                	ld	a5,8(a5)
            count++;
ffffffffc02009be:	2605                	addiw	a2,a2,1
        while (le != list_head) {
ffffffffc02009c0:	fe979ee3          	bne	a5,s1,ffffffffc02009bc <buddy_check+0x56>
        cprintf("Order %d: %d free blocks (size=%d)\n", i, count, 1 << i);
ffffffffc02009c4:	012996bb          	sllw	a3,s3,s2
ffffffffc02009c8:	85ca                	mv	a1,s2
ffffffffc02009ca:	00001517          	auipc	a0,0x1
ffffffffc02009ce:	a8650513          	addi	a0,a0,-1402 # ffffffffc0201450 <etext+0x3bc>
ffffffffc02009d2:	f76ff0ef          	jal	ffffffffc0200148 <cprintf>
    for (int i = 0; i <= buddy_sys.max_order; i++) {
ffffffffc02009d6:	00004797          	auipc	a5,0x4
ffffffffc02009da:	6467a783          	lw	a5,1606(a5) # ffffffffc020501c <buddy_sys+0x4>
ffffffffc02009de:	2905                	addiw	s2,s2,1
ffffffffc02009e0:	04c1                	addi	s1,s1,16
ffffffffc02009e2:	fd27f9e3          	bgeu	a5,s2,ffffffffc02009b4 <buddy_check+0x4e>
ffffffffc02009e6:	02079713          	slli	a4,a5,0x20
ffffffffc02009ea:	01c75793          	srli	a5,a4,0x1c
ffffffffc02009ee:	00004717          	auipc	a4,0x4
ffffffffc02009f2:	64270713          	addi	a4,a4,1602 # ffffffffc0205030 <buddy_sys+0x18>
ffffffffc02009f6:	00e786b3          	add	a3,a5,a4
    size_t total_free = 0;
ffffffffc02009fa:	4581                	li	a1,0
ffffffffc02009fc:	641c                	ld	a5,8(s0)
        while (le != list_head) {
ffffffffc02009fe:	00f40863          	beq	s0,a5,ffffffffc0200a0e <buddy_check+0xa8>
            total_free += page->property;
ffffffffc0200a02:	ff87e703          	lwu	a4,-8(a5)
ffffffffc0200a06:	679c                	ld	a5,8(a5)
ffffffffc0200a08:	95ba                	add	a1,a1,a4
        while (le != list_head) {
ffffffffc0200a0a:	fe879ce3          	bne	a5,s0,ffffffffc0200a02 <buddy_check+0x9c>
    for (int i = 0; i <= buddy_sys.max_order; i++) {
ffffffffc0200a0e:	0441                	addi	s0,s0,16
ffffffffc0200a10:	fe8696e3          	bne	a3,s0,ffffffffc02009fc <buddy_check+0x96>
    }
    
    cprintf("Total free pages: %lu\n", buddy_nr_free_pages());
ffffffffc0200a14:	00001517          	auipc	a0,0x1
ffffffffc0200a18:	a6450513          	addi	a0,a0,-1436 # ffffffffc0201478 <etext+0x3e4>
ffffffffc0200a1c:	f2cff0ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("==========================\n");
}
ffffffffc0200a20:	7402                	ld	s0,32(sp)
ffffffffc0200a22:	70a2                	ld	ra,40(sp)
ffffffffc0200a24:	64e2                	ld	s1,24(sp)
ffffffffc0200a26:	6942                	ld	s2,16(sp)
ffffffffc0200a28:	69a2                	ld	s3,8(sp)
    cprintf("==========================\n");
ffffffffc0200a2a:	00001517          	auipc	a0,0x1
ffffffffc0200a2e:	a6650513          	addi	a0,a0,-1434 # ffffffffc0201490 <etext+0x3fc>
}
ffffffffc0200a32:	6145                	addi	sp,sp,48
    cprintf("==========================\n");
ffffffffc0200a34:	f14ff06f          	j	ffffffffc0200148 <cprintf>

ffffffffc0200a38 <pmm_init>:

static void check_alloc_page(void);

// init_pmm_manager - initialize a pmm_manager instance
static void init_pmm_manager(void) {
    pmm_manager = &buddy_pmm_manager;
ffffffffc0200a38:	00001797          	auipc	a5,0x1
ffffffffc0200a3c:	cb078793          	addi	a5,a5,-848 # ffffffffc02016e8 <buddy_pmm_manager>
    cprintf("memory management: %s\n", pmm_manager->name);
ffffffffc0200a40:	638c                	ld	a1,0(a5)
        init_memmap(pa2page(mem_begin), (mem_end - mem_begin) / PGSIZE);
    }
}

/* pmm_init - initialize the physical memory management */
void pmm_init(void) {
ffffffffc0200a42:	7139                	addi	sp,sp,-64
ffffffffc0200a44:	fc06                	sd	ra,56(sp)
ffffffffc0200a46:	f822                	sd	s0,48(sp)
ffffffffc0200a48:	f426                	sd	s1,40(sp)
ffffffffc0200a4a:	ec4e                	sd	s3,24(sp)
ffffffffc0200a4c:	f04a                	sd	s2,32(sp)
    pmm_manager = &buddy_pmm_manager;
ffffffffc0200a4e:	00004417          	auipc	s0,0x4
ffffffffc0200a52:	69a40413          	addi	s0,s0,1690 # ffffffffc02050e8 <pmm_manager>
    cprintf("memory management: %s\n", pmm_manager->name);
ffffffffc0200a56:	00001517          	auipc	a0,0x1
ffffffffc0200a5a:	a7250513          	addi	a0,a0,-1422 # ffffffffc02014c8 <etext+0x434>
    pmm_manager = &buddy_pmm_manager;
ffffffffc0200a5e:	e01c                	sd	a5,0(s0)
    cprintf("memory management: %s\n", pmm_manager->name);
ffffffffc0200a60:	ee8ff0ef          	jal	ffffffffc0200148 <cprintf>
    pmm_manager->init();
ffffffffc0200a64:	601c                	ld	a5,0(s0)
    va_pa_offset = PHYSICAL_MEMORY_OFFSET;
ffffffffc0200a66:	00004497          	auipc	s1,0x4
ffffffffc0200a6a:	69a48493          	addi	s1,s1,1690 # ffffffffc0205100 <va_pa_offset>
    pmm_manager->init();
ffffffffc0200a6e:	679c                	ld	a5,8(a5)
ffffffffc0200a70:	9782                	jalr	a5
    va_pa_offset = PHYSICAL_MEMORY_OFFSET;
ffffffffc0200a72:	57f5                	li	a5,-3
ffffffffc0200a74:	07fa                	slli	a5,a5,0x1e
ffffffffc0200a76:	e09c                	sd	a5,0(s1)
    uint64_t mem_begin = get_memory_base();
ffffffffc0200a78:	ae3ff0ef          	jal	ffffffffc020055a <get_memory_base>
ffffffffc0200a7c:	89aa                	mv	s3,a0
    uint64_t mem_size  = get_memory_size();
ffffffffc0200a7e:	ae7ff0ef          	jal	ffffffffc0200564 <get_memory_size>
    if (mem_size == 0) {
ffffffffc0200a82:	14050c63          	beqz	a0,ffffffffc0200bda <pmm_init+0x1a2>
    uint64_t mem_end   = mem_begin + mem_size;
ffffffffc0200a86:	00a98933          	add	s2,s3,a0
ffffffffc0200a8a:	e42a                	sd	a0,8(sp)
    cprintf("physcial memory map:\n");
ffffffffc0200a8c:	00001517          	auipc	a0,0x1
ffffffffc0200a90:	a8450513          	addi	a0,a0,-1404 # ffffffffc0201510 <etext+0x47c>
ffffffffc0200a94:	eb4ff0ef          	jal	ffffffffc0200148 <cprintf>
    cprintf("  memory: 0x%016lx, [0x%016lx, 0x%016lx].\n", mem_size, mem_begin,
ffffffffc0200a98:	65a2                	ld	a1,8(sp)
ffffffffc0200a9a:	864e                	mv	a2,s3
ffffffffc0200a9c:	fff90693          	addi	a3,s2,-1
ffffffffc0200aa0:	00001517          	auipc	a0,0x1
ffffffffc0200aa4:	a8850513          	addi	a0,a0,-1400 # ffffffffc0201528 <etext+0x494>
ffffffffc0200aa8:	ea0ff0ef          	jal	ffffffffc0200148 <cprintf>
    if (maxpa > KERNTOP) {
ffffffffc0200aac:	c80007b7          	lui	a5,0xc8000
ffffffffc0200ab0:	85ca                	mv	a1,s2
ffffffffc0200ab2:	0d27e263          	bltu	a5,s2,ffffffffc0200b76 <pmm_init+0x13e>
ffffffffc0200ab6:	77fd                	lui	a5,0xfffff
    pages = (struct Page *)ROUNDUP((void *)end, PGSIZE);
ffffffffc0200ab8:	00005697          	auipc	a3,0x5
ffffffffc0200abc:	65f68693          	addi	a3,a3,1631 # ffffffffc0206117 <end+0xfff>
ffffffffc0200ac0:	8efd                	and	a3,a3,a5
    npage = maxpa / PGSIZE;
ffffffffc0200ac2:	81b1                	srli	a1,a1,0xc
    for (size_t i = 0; i < npage - nbase; i++) {
ffffffffc0200ac4:	fff80837          	lui	a6,0xfff80
    npage = maxpa / PGSIZE;
ffffffffc0200ac8:	00004797          	auipc	a5,0x4
ffffffffc0200acc:	64b7b023          	sd	a1,1600(a5) # ffffffffc0205108 <npage>
    pages = (struct Page *)ROUNDUP((void *)end, PGSIZE);
ffffffffc0200ad0:	00004797          	auipc	a5,0x4
ffffffffc0200ad4:	64d7b023          	sd	a3,1600(a5) # ffffffffc0205110 <pages>
    for (size_t i = 0; i < npage - nbase; i++) {
ffffffffc0200ad8:	982e                	add	a6,a6,a1
    pages = (struct Page *)ROUNDUP((void *)end, PGSIZE);
ffffffffc0200ada:	88b6                	mv	a7,a3
    for (size_t i = 0; i < npage - nbase; i++) {
ffffffffc0200adc:	02080963          	beqz	a6,ffffffffc0200b0e <pmm_init+0xd6>
ffffffffc0200ae0:	00259613          	slli	a2,a1,0x2
ffffffffc0200ae4:	962e                	add	a2,a2,a1
ffffffffc0200ae6:	fec007b7          	lui	a5,0xfec00
ffffffffc0200aea:	97b6                	add	a5,a5,a3
ffffffffc0200aec:	060e                	slli	a2,a2,0x3
ffffffffc0200aee:	963e                	add	a2,a2,a5
ffffffffc0200af0:	87b6                	mv	a5,a3
        SetPageReserved(pages + i);
ffffffffc0200af2:	6798                	ld	a4,8(a5)
    for (size_t i = 0; i < npage - nbase; i++) {
ffffffffc0200af4:	02878793          	addi	a5,a5,40 # fffffffffec00028 <end+0x3e9faf10>
        SetPageReserved(pages + i);
ffffffffc0200af8:	00176713          	ori	a4,a4,1
ffffffffc0200afc:	fee7b023          	sd	a4,-32(a5)
    for (size_t i = 0; i < npage - nbase; i++) {
ffffffffc0200b00:	fec799e3          	bne	a5,a2,ffffffffc0200af2 <pmm_init+0xba>
    uintptr_t freemem = PADDR((uintptr_t)pages + sizeof(struct Page) * (npage - nbase));
ffffffffc0200b04:	00281793          	slli	a5,a6,0x2
ffffffffc0200b08:	97c2                	add	a5,a5,a6
ffffffffc0200b0a:	078e                	slli	a5,a5,0x3
ffffffffc0200b0c:	96be                	add	a3,a3,a5
ffffffffc0200b0e:	c02007b7          	lui	a5,0xc0200
ffffffffc0200b12:	0af6e863          	bltu	a3,a5,ffffffffc0200bc2 <pmm_init+0x18a>
ffffffffc0200b16:	6098                	ld	a4,0(s1)
    mem_end = ROUNDDOWN(mem_end, PGSIZE);
ffffffffc0200b18:	77fd                	lui	a5,0xfffff
ffffffffc0200b1a:	00f97933          	and	s2,s2,a5
    uintptr_t freemem = PADDR((uintptr_t)pages + sizeof(struct Page) * (npage - nbase));
ffffffffc0200b1e:	8e99                	sub	a3,a3,a4
    if (freemem < mem_end) {
ffffffffc0200b20:	0526ed63          	bltu	a3,s2,ffffffffc0200b7a <pmm_init+0x142>
    satp_physical = PADDR(satp_virtual);
    cprintf("satp virtual address: 0x%016lx\nsatp physical address: 0x%016lx\n", satp_virtual, satp_physical);
}

static void check_alloc_page(void) {
    pmm_manager->check();
ffffffffc0200b24:	601c                	ld	a5,0(s0)
ffffffffc0200b26:	7b9c                	ld	a5,48(a5)
ffffffffc0200b28:	9782                	jalr	a5
    cprintf("check_alloc_page() succeeded!\n");
ffffffffc0200b2a:	00001517          	auipc	a0,0x1
ffffffffc0200b2e:	a8650513          	addi	a0,a0,-1402 # ffffffffc02015b0 <etext+0x51c>
ffffffffc0200b32:	e16ff0ef          	jal	ffffffffc0200148 <cprintf>
    satp_virtual = (pte_t*)boot_page_table_sv39;
ffffffffc0200b36:	00003597          	auipc	a1,0x3
ffffffffc0200b3a:	4ca58593          	addi	a1,a1,1226 # ffffffffc0204000 <boot_page_table_sv39>
ffffffffc0200b3e:	00004797          	auipc	a5,0x4
ffffffffc0200b42:	5ab7bd23          	sd	a1,1466(a5) # ffffffffc02050f8 <satp_virtual>
    satp_physical = PADDR(satp_virtual);
ffffffffc0200b46:	c02007b7          	lui	a5,0xc0200
ffffffffc0200b4a:	0af5e463          	bltu	a1,a5,ffffffffc0200bf2 <pmm_init+0x1ba>
ffffffffc0200b4e:	609c                	ld	a5,0(s1)
}
ffffffffc0200b50:	7442                	ld	s0,48(sp)
ffffffffc0200b52:	70e2                	ld	ra,56(sp)
ffffffffc0200b54:	74a2                	ld	s1,40(sp)
ffffffffc0200b56:	7902                	ld	s2,32(sp)
ffffffffc0200b58:	69e2                	ld	s3,24(sp)
    satp_physical = PADDR(satp_virtual);
ffffffffc0200b5a:	40f586b3          	sub	a3,a1,a5
ffffffffc0200b5e:	00004797          	auipc	a5,0x4
ffffffffc0200b62:	58d7b923          	sd	a3,1426(a5) # ffffffffc02050f0 <satp_physical>
    cprintf("satp virtual address: 0x%016lx\nsatp physical address: 0x%016lx\n", satp_virtual, satp_physical);
ffffffffc0200b66:	00001517          	auipc	a0,0x1
ffffffffc0200b6a:	a6a50513          	addi	a0,a0,-1430 # ffffffffc02015d0 <etext+0x53c>
ffffffffc0200b6e:	8636                	mv	a2,a3
}
ffffffffc0200b70:	6121                	addi	sp,sp,64
    cprintf("satp virtual address: 0x%016lx\nsatp physical address: 0x%016lx\n", satp_virtual, satp_physical);
ffffffffc0200b72:	dd6ff06f          	j	ffffffffc0200148 <cprintf>
    if (maxpa > KERNTOP) {
ffffffffc0200b76:	85be                	mv	a1,a5
ffffffffc0200b78:	bf3d                	j	ffffffffc0200ab6 <pmm_init+0x7e>
    mem_begin = ROUNDUP(freemem, PGSIZE);
ffffffffc0200b7a:	6705                	lui	a4,0x1
ffffffffc0200b7c:	177d                	addi	a4,a4,-1 # fff <kern_entry-0xffffffffc01ff001>
ffffffffc0200b7e:	96ba                	add	a3,a3,a4
ffffffffc0200b80:	8efd                	and	a3,a3,a5
static inline int page_ref_dec(struct Page *page) {
    page->ref -= 1;
    return page->ref;
}
static inline struct Page *pa2page(uintptr_t pa) {
    if (PPN(pa) >= npage) {
ffffffffc0200b82:	00c6d793          	srli	a5,a3,0xc
ffffffffc0200b86:	02b7f263          	bgeu	a5,a1,ffffffffc0200baa <pmm_init+0x172>
    pmm_manager->init_memmap(base, n);
ffffffffc0200b8a:	6018                	ld	a4,0(s0)
        panic("pa2page called with invalid pa");
    }
    return &pages[PPN(pa) - nbase];
ffffffffc0200b8c:	fff80637          	lui	a2,0xfff80
ffffffffc0200b90:	97b2                	add	a5,a5,a2
ffffffffc0200b92:	00279513          	slli	a0,a5,0x2
ffffffffc0200b96:	953e                	add	a0,a0,a5
ffffffffc0200b98:	6b1c                	ld	a5,16(a4)
        init_memmap(pa2page(mem_begin), (mem_end - mem_begin) / PGSIZE);
ffffffffc0200b9a:	40d90933          	sub	s2,s2,a3
ffffffffc0200b9e:	050e                	slli	a0,a0,0x3
    pmm_manager->init_memmap(base, n);
ffffffffc0200ba0:	00c95593          	srli	a1,s2,0xc
ffffffffc0200ba4:	9546                	add	a0,a0,a7
ffffffffc0200ba6:	9782                	jalr	a5
}
ffffffffc0200ba8:	bfb5                	j	ffffffffc0200b24 <pmm_init+0xec>
        panic("pa2page called with invalid pa");
ffffffffc0200baa:	00001617          	auipc	a2,0x1
ffffffffc0200bae:	9d660613          	addi	a2,a2,-1578 # ffffffffc0201580 <etext+0x4ec>
ffffffffc0200bb2:	06a00593          	li	a1,106
ffffffffc0200bb6:	00001517          	auipc	a0,0x1
ffffffffc0200bba:	9ea50513          	addi	a0,a0,-1558 # ffffffffc02015a0 <etext+0x50c>
ffffffffc0200bbe:	e0aff0ef          	jal	ffffffffc02001c8 <__panic>
    uintptr_t freemem = PADDR((uintptr_t)pages + sizeof(struct Page) * (npage - nbase));
ffffffffc0200bc2:	00001617          	auipc	a2,0x1
ffffffffc0200bc6:	99660613          	addi	a2,a2,-1642 # ffffffffc0201558 <etext+0x4c4>
ffffffffc0200bca:	05f00593          	li	a1,95
ffffffffc0200bce:	00001517          	auipc	a0,0x1
ffffffffc0200bd2:	93250513          	addi	a0,a0,-1742 # ffffffffc0201500 <etext+0x46c>
ffffffffc0200bd6:	df2ff0ef          	jal	ffffffffc02001c8 <__panic>
        panic("DTB memory info not available");
ffffffffc0200bda:	00001617          	auipc	a2,0x1
ffffffffc0200bde:	90660613          	addi	a2,a2,-1786 # ffffffffc02014e0 <etext+0x44c>
ffffffffc0200be2:	04700593          	li	a1,71
ffffffffc0200be6:	00001517          	auipc	a0,0x1
ffffffffc0200bea:	91a50513          	addi	a0,a0,-1766 # ffffffffc0201500 <etext+0x46c>
ffffffffc0200bee:	ddaff0ef          	jal	ffffffffc02001c8 <__panic>
    satp_physical = PADDR(satp_virtual);
ffffffffc0200bf2:	86ae                	mv	a3,a1
ffffffffc0200bf4:	00001617          	auipc	a2,0x1
ffffffffc0200bf8:	96460613          	addi	a2,a2,-1692 # ffffffffc0201558 <etext+0x4c4>
ffffffffc0200bfc:	07a00593          	li	a1,122
ffffffffc0200c00:	00001517          	auipc	a0,0x1
ffffffffc0200c04:	90050513          	addi	a0,a0,-1792 # ffffffffc0201500 <etext+0x46c>
ffffffffc0200c08:	dc0ff0ef          	jal	ffffffffc02001c8 <__panic>

ffffffffc0200c0c <printnum>:
 * @width:      maximum number of digits, if the actual width is less than @width, use @padc instead
 * @padc:       character that padded on the left if the actual width is less than @width
 * */
static void
printnum(void (*putch)(int, void*), void *putdat,
        unsigned long long num, unsigned base, int width, int padc) {
ffffffffc0200c0c:	7179                	addi	sp,sp,-48
    unsigned long long result = num;
    unsigned mod = do_div(result, base);
ffffffffc0200c0e:	02069813          	slli	a6,a3,0x20
        unsigned long long num, unsigned base, int width, int padc) {
ffffffffc0200c12:	f022                	sd	s0,32(sp)
ffffffffc0200c14:	ec26                	sd	s1,24(sp)
ffffffffc0200c16:	e84a                	sd	s2,16(sp)
ffffffffc0200c18:	e052                	sd	s4,0(sp)
    unsigned mod = do_div(result, base);
ffffffffc0200c1a:	02085813          	srli	a6,a6,0x20
        unsigned long long num, unsigned base, int width, int padc) {
ffffffffc0200c1e:	f406                	sd	ra,40(sp)
    unsigned mod = do_div(result, base);
ffffffffc0200c20:	03067a33          	remu	s4,a2,a6
    // first recursively print all preceding (more significant) digits
    if (num >= base) {
        printnum(putch, putdat, result, base, width - 1, padc);
    } else {
        // print any needed pad characters before first digit
        while (-- width > 0)
ffffffffc0200c24:	fff7041b          	addiw	s0,a4,-1
        unsigned long long num, unsigned base, int width, int padc) {
ffffffffc0200c28:	84aa                	mv	s1,a0
ffffffffc0200c2a:	892e                	mv	s2,a1
    if (num >= base) {
ffffffffc0200c2c:	03067d63          	bgeu	a2,a6,ffffffffc0200c66 <printnum+0x5a>
ffffffffc0200c30:	e44e                	sd	s3,8(sp)
ffffffffc0200c32:	89be                	mv	s3,a5
        while (-- width > 0)
ffffffffc0200c34:	4785                	li	a5,1
ffffffffc0200c36:	00e7d763          	bge	a5,a4,ffffffffc0200c44 <printnum+0x38>
            putch(padc, putdat);
ffffffffc0200c3a:	85ca                	mv	a1,s2
ffffffffc0200c3c:	854e                	mv	a0,s3
        while (-- width > 0)
ffffffffc0200c3e:	347d                	addiw	s0,s0,-1
            putch(padc, putdat);
ffffffffc0200c40:	9482                	jalr	s1
        while (-- width > 0)
ffffffffc0200c42:	fc65                	bnez	s0,ffffffffc0200c3a <printnum+0x2e>
ffffffffc0200c44:	69a2                	ld	s3,8(sp)
    }
    // then print this (the least significant) digit
    putch("0123456789abcdef"[mod], putdat);
ffffffffc0200c46:	00001797          	auipc	a5,0x1
ffffffffc0200c4a:	9ca78793          	addi	a5,a5,-1590 # ffffffffc0201610 <etext+0x57c>
ffffffffc0200c4e:	97d2                	add	a5,a5,s4
}
ffffffffc0200c50:	7402                	ld	s0,32(sp)
    putch("0123456789abcdef"[mod], putdat);
ffffffffc0200c52:	0007c503          	lbu	a0,0(a5)
}
ffffffffc0200c56:	70a2                	ld	ra,40(sp)
ffffffffc0200c58:	6a02                	ld	s4,0(sp)
    putch("0123456789abcdef"[mod], putdat);
ffffffffc0200c5a:	85ca                	mv	a1,s2
ffffffffc0200c5c:	87a6                	mv	a5,s1
}
ffffffffc0200c5e:	6942                	ld	s2,16(sp)
ffffffffc0200c60:	64e2                	ld	s1,24(sp)
ffffffffc0200c62:	6145                	addi	sp,sp,48
    putch("0123456789abcdef"[mod], putdat);
ffffffffc0200c64:	8782                	jr	a5
        printnum(putch, putdat, result, base, width - 1, padc);
ffffffffc0200c66:	03065633          	divu	a2,a2,a6
ffffffffc0200c6a:	8722                	mv	a4,s0
ffffffffc0200c6c:	fa1ff0ef          	jal	ffffffffc0200c0c <printnum>
ffffffffc0200c70:	bfd9                	j	ffffffffc0200c46 <printnum+0x3a>

ffffffffc0200c72 <vprintfmt>:
 *
 * Call this function if you are already dealing with a va_list.
 * Or you probably want printfmt() instead.
 * */
void
vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list ap) {
ffffffffc0200c72:	7119                	addi	sp,sp,-128
ffffffffc0200c74:	f4a6                	sd	s1,104(sp)
ffffffffc0200c76:	f0ca                	sd	s2,96(sp)
ffffffffc0200c78:	ecce                	sd	s3,88(sp)
ffffffffc0200c7a:	e8d2                	sd	s4,80(sp)
ffffffffc0200c7c:	e4d6                	sd	s5,72(sp)
ffffffffc0200c7e:	e0da                	sd	s6,64(sp)
ffffffffc0200c80:	f862                	sd	s8,48(sp)
ffffffffc0200c82:	fc86                	sd	ra,120(sp)
ffffffffc0200c84:	f8a2                	sd	s0,112(sp)
ffffffffc0200c86:	fc5e                	sd	s7,56(sp)
ffffffffc0200c88:	f466                	sd	s9,40(sp)
ffffffffc0200c8a:	f06a                	sd	s10,32(sp)
ffffffffc0200c8c:	ec6e                	sd	s11,24(sp)
ffffffffc0200c8e:	84aa                	mv	s1,a0
ffffffffc0200c90:	8c32                	mv	s8,a2
ffffffffc0200c92:	8a36                	mv	s4,a3
ffffffffc0200c94:	892e                	mv	s2,a1
    register int ch, err;
    unsigned long long num;
    int base, width, precision, lflag, altflag;

    while (1) {
        while ((ch = *(unsigned char *)fmt ++) != '%') {
ffffffffc0200c96:	02500993          	li	s3,37
        char padc = ' ';
        width = precision = -1;
        lflag = altflag = 0;

    reswitch:
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0200c9a:	05500b13          	li	s6,85
ffffffffc0200c9e:	00001a97          	auipc	s5,0x1
ffffffffc0200ca2:	a82a8a93          	addi	s5,s5,-1406 # ffffffffc0201720 <buddy_pmm_manager+0x38>
        while ((ch = *(unsigned char *)fmt ++) != '%') {
ffffffffc0200ca6:	000c4503          	lbu	a0,0(s8)
ffffffffc0200caa:	001c0413          	addi	s0,s8,1
ffffffffc0200cae:	01350a63          	beq	a0,s3,ffffffffc0200cc2 <vprintfmt+0x50>
            if (ch == '\0') {
ffffffffc0200cb2:	cd0d                	beqz	a0,ffffffffc0200cec <vprintfmt+0x7a>
            putch(ch, putdat);
ffffffffc0200cb4:	85ca                	mv	a1,s2
ffffffffc0200cb6:	9482                	jalr	s1
        while ((ch = *(unsigned char *)fmt ++) != '%') {
ffffffffc0200cb8:	00044503          	lbu	a0,0(s0)
ffffffffc0200cbc:	0405                	addi	s0,s0,1
ffffffffc0200cbe:	ff351ae3          	bne	a0,s3,ffffffffc0200cb2 <vprintfmt+0x40>
        width = precision = -1;
ffffffffc0200cc2:	5cfd                	li	s9,-1
ffffffffc0200cc4:	8d66                	mv	s10,s9
        char padc = ' ';
ffffffffc0200cc6:	02000d93          	li	s11,32
        lflag = altflag = 0;
ffffffffc0200cca:	4b81                	li	s7,0
ffffffffc0200ccc:	4781                	li	a5,0
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0200cce:	00044683          	lbu	a3,0(s0)
ffffffffc0200cd2:	00140c13          	addi	s8,s0,1
ffffffffc0200cd6:	fdd6859b          	addiw	a1,a3,-35
ffffffffc0200cda:	0ff5f593          	zext.b	a1,a1
ffffffffc0200cde:	02bb6663          	bltu	s6,a1,ffffffffc0200d0a <vprintfmt+0x98>
ffffffffc0200ce2:	058a                	slli	a1,a1,0x2
ffffffffc0200ce4:	95d6                	add	a1,a1,s5
ffffffffc0200ce6:	4198                	lw	a4,0(a1)
ffffffffc0200ce8:	9756                	add	a4,a4,s5
ffffffffc0200cea:	8702                	jr	a4
            for (fmt --; fmt[-1] != '%'; fmt --)
                /* do nothing */;
            break;
        }
    }
}
ffffffffc0200cec:	70e6                	ld	ra,120(sp)
ffffffffc0200cee:	7446                	ld	s0,112(sp)
ffffffffc0200cf0:	74a6                	ld	s1,104(sp)
ffffffffc0200cf2:	7906                	ld	s2,96(sp)
ffffffffc0200cf4:	69e6                	ld	s3,88(sp)
ffffffffc0200cf6:	6a46                	ld	s4,80(sp)
ffffffffc0200cf8:	6aa6                	ld	s5,72(sp)
ffffffffc0200cfa:	6b06                	ld	s6,64(sp)
ffffffffc0200cfc:	7be2                	ld	s7,56(sp)
ffffffffc0200cfe:	7c42                	ld	s8,48(sp)
ffffffffc0200d00:	7ca2                	ld	s9,40(sp)
ffffffffc0200d02:	7d02                	ld	s10,32(sp)
ffffffffc0200d04:	6de2                	ld	s11,24(sp)
ffffffffc0200d06:	6109                	addi	sp,sp,128
ffffffffc0200d08:	8082                	ret
            putch('%', putdat);
ffffffffc0200d0a:	85ca                	mv	a1,s2
ffffffffc0200d0c:	02500513          	li	a0,37
ffffffffc0200d10:	9482                	jalr	s1
            for (fmt --; fmt[-1] != '%'; fmt --)
ffffffffc0200d12:	fff44783          	lbu	a5,-1(s0)
ffffffffc0200d16:	02500713          	li	a4,37
ffffffffc0200d1a:	8c22                	mv	s8,s0
ffffffffc0200d1c:	f8e785e3          	beq	a5,a4,ffffffffc0200ca6 <vprintfmt+0x34>
ffffffffc0200d20:	ffec4783          	lbu	a5,-2(s8)
ffffffffc0200d24:	1c7d                	addi	s8,s8,-1
ffffffffc0200d26:	fee79de3          	bne	a5,a4,ffffffffc0200d20 <vprintfmt+0xae>
ffffffffc0200d2a:	bfb5                	j	ffffffffc0200ca6 <vprintfmt+0x34>
                ch = *fmt;
ffffffffc0200d2c:	00144603          	lbu	a2,1(s0)
                if (ch < '0' || ch > '9') {
ffffffffc0200d30:	4525                	li	a0,9
                precision = precision * 10 + ch - '0';
ffffffffc0200d32:	fd068c9b          	addiw	s9,a3,-48
                if (ch < '0' || ch > '9') {
ffffffffc0200d36:	fd06071b          	addiw	a4,a2,-48
ffffffffc0200d3a:	24e56a63          	bltu	a0,a4,ffffffffc0200f8e <vprintfmt+0x31c>
                ch = *fmt;
ffffffffc0200d3e:	2601                	sext.w	a2,a2
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0200d40:	8462                	mv	s0,s8
                precision = precision * 10 + ch - '0';
ffffffffc0200d42:	002c971b          	slliw	a4,s9,0x2
                ch = *fmt;
ffffffffc0200d46:	00144683          	lbu	a3,1(s0)
                precision = precision * 10 + ch - '0';
ffffffffc0200d4a:	0197073b          	addw	a4,a4,s9
ffffffffc0200d4e:	0017171b          	slliw	a4,a4,0x1
ffffffffc0200d52:	9f31                	addw	a4,a4,a2
                if (ch < '0' || ch > '9') {
ffffffffc0200d54:	fd06859b          	addiw	a1,a3,-48
            for (precision = 0; ; ++ fmt) {
ffffffffc0200d58:	0405                	addi	s0,s0,1
                precision = precision * 10 + ch - '0';
ffffffffc0200d5a:	fd070c9b          	addiw	s9,a4,-48
                ch = *fmt;
ffffffffc0200d5e:	0006861b          	sext.w	a2,a3
                if (ch < '0' || ch > '9') {
ffffffffc0200d62:	feb570e3          	bgeu	a0,a1,ffffffffc0200d42 <vprintfmt+0xd0>
            if (width < 0)
ffffffffc0200d66:	f60d54e3          	bgez	s10,ffffffffc0200cce <vprintfmt+0x5c>
                width = precision, precision = -1;
ffffffffc0200d6a:	8d66                	mv	s10,s9
ffffffffc0200d6c:	5cfd                	li	s9,-1
ffffffffc0200d6e:	b785                	j	ffffffffc0200cce <vprintfmt+0x5c>
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0200d70:	8db6                	mv	s11,a3
ffffffffc0200d72:	8462                	mv	s0,s8
ffffffffc0200d74:	bfa9                	j	ffffffffc0200cce <vprintfmt+0x5c>
ffffffffc0200d76:	8462                	mv	s0,s8
            altflag = 1;
ffffffffc0200d78:	4b85                	li	s7,1
            goto reswitch;
ffffffffc0200d7a:	bf91                	j	ffffffffc0200cce <vprintfmt+0x5c>
    if (lflag >= 2) {
ffffffffc0200d7c:	4705                	li	a4,1
            precision = va_arg(ap, int);
ffffffffc0200d7e:	008a0593          	addi	a1,s4,8
    if (lflag >= 2) {
ffffffffc0200d82:	00f74463          	blt	a4,a5,ffffffffc0200d8a <vprintfmt+0x118>
    else if (lflag) {
ffffffffc0200d86:	1a078763          	beqz	a5,ffffffffc0200f34 <vprintfmt+0x2c2>
        return va_arg(*ap, unsigned long);
ffffffffc0200d8a:	000a3603          	ld	a2,0(s4)
ffffffffc0200d8e:	46c1                	li	a3,16
ffffffffc0200d90:	8a2e                	mv	s4,a1
            printnum(putch, putdat, num, base, width, padc);
ffffffffc0200d92:	000d879b          	sext.w	a5,s11
ffffffffc0200d96:	876a                	mv	a4,s10
ffffffffc0200d98:	85ca                	mv	a1,s2
ffffffffc0200d9a:	8526                	mv	a0,s1
ffffffffc0200d9c:	e71ff0ef          	jal	ffffffffc0200c0c <printnum>
            break;
ffffffffc0200da0:	b719                	j	ffffffffc0200ca6 <vprintfmt+0x34>
            putch(va_arg(ap, int), putdat);
ffffffffc0200da2:	000a2503          	lw	a0,0(s4)
ffffffffc0200da6:	85ca                	mv	a1,s2
ffffffffc0200da8:	0a21                	addi	s4,s4,8
ffffffffc0200daa:	9482                	jalr	s1
            break;
ffffffffc0200dac:	bded                	j	ffffffffc0200ca6 <vprintfmt+0x34>
    if (lflag >= 2) {
ffffffffc0200dae:	4705                	li	a4,1
            precision = va_arg(ap, int);
ffffffffc0200db0:	008a0593          	addi	a1,s4,8
    if (lflag >= 2) {
ffffffffc0200db4:	00f74463          	blt	a4,a5,ffffffffc0200dbc <vprintfmt+0x14a>
    else if (lflag) {
ffffffffc0200db8:	16078963          	beqz	a5,ffffffffc0200f2a <vprintfmt+0x2b8>
        return va_arg(*ap, unsigned long);
ffffffffc0200dbc:	000a3603          	ld	a2,0(s4)
ffffffffc0200dc0:	46a9                	li	a3,10
ffffffffc0200dc2:	8a2e                	mv	s4,a1
ffffffffc0200dc4:	b7f9                	j	ffffffffc0200d92 <vprintfmt+0x120>
            putch('0', putdat);
ffffffffc0200dc6:	85ca                	mv	a1,s2
ffffffffc0200dc8:	03000513          	li	a0,48
ffffffffc0200dcc:	9482                	jalr	s1
            putch('x', putdat);
ffffffffc0200dce:	85ca                	mv	a1,s2
ffffffffc0200dd0:	07800513          	li	a0,120
ffffffffc0200dd4:	9482                	jalr	s1
            num = (unsigned long long)(uintptr_t)va_arg(ap, void *);
ffffffffc0200dd6:	000a3603          	ld	a2,0(s4)
            goto number;
ffffffffc0200dda:	46c1                	li	a3,16
            num = (unsigned long long)(uintptr_t)va_arg(ap, void *);
ffffffffc0200ddc:	0a21                	addi	s4,s4,8
            goto number;
ffffffffc0200dde:	bf55                	j	ffffffffc0200d92 <vprintfmt+0x120>
            putch(ch, putdat);
ffffffffc0200de0:	85ca                	mv	a1,s2
ffffffffc0200de2:	02500513          	li	a0,37
ffffffffc0200de6:	9482                	jalr	s1
            break;
ffffffffc0200de8:	bd7d                	j	ffffffffc0200ca6 <vprintfmt+0x34>
            precision = va_arg(ap, int);
ffffffffc0200dea:	000a2c83          	lw	s9,0(s4)
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0200dee:	8462                	mv	s0,s8
            precision = va_arg(ap, int);
ffffffffc0200df0:	0a21                	addi	s4,s4,8
            goto process_precision;
ffffffffc0200df2:	bf95                	j	ffffffffc0200d66 <vprintfmt+0xf4>
    if (lflag >= 2) {
ffffffffc0200df4:	4705                	li	a4,1
            precision = va_arg(ap, int);
ffffffffc0200df6:	008a0593          	addi	a1,s4,8
    if (lflag >= 2) {
ffffffffc0200dfa:	00f74463          	blt	a4,a5,ffffffffc0200e02 <vprintfmt+0x190>
    else if (lflag) {
ffffffffc0200dfe:	12078163          	beqz	a5,ffffffffc0200f20 <vprintfmt+0x2ae>
        return va_arg(*ap, unsigned long);
ffffffffc0200e02:	000a3603          	ld	a2,0(s4)
ffffffffc0200e06:	46a1                	li	a3,8
ffffffffc0200e08:	8a2e                	mv	s4,a1
ffffffffc0200e0a:	b761                	j	ffffffffc0200d92 <vprintfmt+0x120>
            if (width < 0)
ffffffffc0200e0c:	876a                	mv	a4,s10
ffffffffc0200e0e:	000d5363          	bgez	s10,ffffffffc0200e14 <vprintfmt+0x1a2>
ffffffffc0200e12:	4701                	li	a4,0
ffffffffc0200e14:	00070d1b          	sext.w	s10,a4
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0200e18:	8462                	mv	s0,s8
            goto reswitch;
ffffffffc0200e1a:	bd55                	j	ffffffffc0200cce <vprintfmt+0x5c>
            if (width > 0 && padc != '-') {
ffffffffc0200e1c:	000d841b          	sext.w	s0,s11
ffffffffc0200e20:	fd340793          	addi	a5,s0,-45
ffffffffc0200e24:	00f037b3          	snez	a5,a5
ffffffffc0200e28:	01a02733          	sgtz	a4,s10
            if ((p = va_arg(ap, char *)) == NULL) {
ffffffffc0200e2c:	000a3d83          	ld	s11,0(s4)
            if (width > 0 && padc != '-') {
ffffffffc0200e30:	8f7d                	and	a4,a4,a5
            if ((p = va_arg(ap, char *)) == NULL) {
ffffffffc0200e32:	008a0793          	addi	a5,s4,8
ffffffffc0200e36:	e43e                	sd	a5,8(sp)
ffffffffc0200e38:	100d8c63          	beqz	s11,ffffffffc0200f50 <vprintfmt+0x2de>
            if (width > 0 && padc != '-') {
ffffffffc0200e3c:	12071363          	bnez	a4,ffffffffc0200f62 <vprintfmt+0x2f0>
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0200e40:	000dc783          	lbu	a5,0(s11)
ffffffffc0200e44:	0007851b          	sext.w	a0,a5
ffffffffc0200e48:	c78d                	beqz	a5,ffffffffc0200e72 <vprintfmt+0x200>
ffffffffc0200e4a:	0d85                	addi	s11,s11,1
ffffffffc0200e4c:	547d                	li	s0,-1
                if (altflag && (ch < ' ' || ch > '~')) {
ffffffffc0200e4e:	05e00a13          	li	s4,94
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0200e52:	000cc563          	bltz	s9,ffffffffc0200e5c <vprintfmt+0x1ea>
ffffffffc0200e56:	3cfd                	addiw	s9,s9,-1
ffffffffc0200e58:	008c8d63          	beq	s9,s0,ffffffffc0200e72 <vprintfmt+0x200>
                if (altflag && (ch < ' ' || ch > '~')) {
ffffffffc0200e5c:	020b9663          	bnez	s7,ffffffffc0200e88 <vprintfmt+0x216>
                    putch(ch, putdat);
ffffffffc0200e60:	85ca                	mv	a1,s2
ffffffffc0200e62:	9482                	jalr	s1
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0200e64:	000dc783          	lbu	a5,0(s11)
ffffffffc0200e68:	0d85                	addi	s11,s11,1
ffffffffc0200e6a:	3d7d                	addiw	s10,s10,-1
ffffffffc0200e6c:	0007851b          	sext.w	a0,a5
ffffffffc0200e70:	f3ed                	bnez	a5,ffffffffc0200e52 <vprintfmt+0x1e0>
            for (; width > 0; width --) {
ffffffffc0200e72:	01a05963          	blez	s10,ffffffffc0200e84 <vprintfmt+0x212>
                putch(' ', putdat);
ffffffffc0200e76:	85ca                	mv	a1,s2
ffffffffc0200e78:	02000513          	li	a0,32
            for (; width > 0; width --) {
ffffffffc0200e7c:	3d7d                	addiw	s10,s10,-1
                putch(' ', putdat);
ffffffffc0200e7e:	9482                	jalr	s1
            for (; width > 0; width --) {
ffffffffc0200e80:	fe0d1be3          	bnez	s10,ffffffffc0200e76 <vprintfmt+0x204>
            if ((p = va_arg(ap, char *)) == NULL) {
ffffffffc0200e84:	6a22                	ld	s4,8(sp)
ffffffffc0200e86:	b505                	j	ffffffffc0200ca6 <vprintfmt+0x34>
                if (altflag && (ch < ' ' || ch > '~')) {
ffffffffc0200e88:	3781                	addiw	a5,a5,-32
ffffffffc0200e8a:	fcfa7be3          	bgeu	s4,a5,ffffffffc0200e60 <vprintfmt+0x1ee>
                    putch('?', putdat);
ffffffffc0200e8e:	03f00513          	li	a0,63
ffffffffc0200e92:	85ca                	mv	a1,s2
ffffffffc0200e94:	9482                	jalr	s1
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0200e96:	000dc783          	lbu	a5,0(s11)
ffffffffc0200e9a:	0d85                	addi	s11,s11,1
ffffffffc0200e9c:	3d7d                	addiw	s10,s10,-1
ffffffffc0200e9e:	0007851b          	sext.w	a0,a5
ffffffffc0200ea2:	dbe1                	beqz	a5,ffffffffc0200e72 <vprintfmt+0x200>
ffffffffc0200ea4:	fa0cd9e3          	bgez	s9,ffffffffc0200e56 <vprintfmt+0x1e4>
ffffffffc0200ea8:	b7c5                	j	ffffffffc0200e88 <vprintfmt+0x216>
            if (err < 0) {
ffffffffc0200eaa:	000a2783          	lw	a5,0(s4)
            if (err > MAXERROR || (p = error_string[err]) == NULL) {
ffffffffc0200eae:	4619                	li	a2,6
            err = va_arg(ap, int);
ffffffffc0200eb0:	0a21                	addi	s4,s4,8
            if (err < 0) {
ffffffffc0200eb2:	41f7d71b          	sraiw	a4,a5,0x1f
ffffffffc0200eb6:	8fb9                	xor	a5,a5,a4
ffffffffc0200eb8:	40e786bb          	subw	a3,a5,a4
            if (err > MAXERROR || (p = error_string[err]) == NULL) {
ffffffffc0200ebc:	02d64563          	blt	a2,a3,ffffffffc0200ee6 <vprintfmt+0x274>
ffffffffc0200ec0:	00001797          	auipc	a5,0x1
ffffffffc0200ec4:	9b878793          	addi	a5,a5,-1608 # ffffffffc0201878 <error_string>
ffffffffc0200ec8:	00369713          	slli	a4,a3,0x3
ffffffffc0200ecc:	97ba                	add	a5,a5,a4
ffffffffc0200ece:	639c                	ld	a5,0(a5)
ffffffffc0200ed0:	cb99                	beqz	a5,ffffffffc0200ee6 <vprintfmt+0x274>
                printfmt(putch, putdat, "%s", p);
ffffffffc0200ed2:	86be                	mv	a3,a5
ffffffffc0200ed4:	00000617          	auipc	a2,0x0
ffffffffc0200ed8:	76c60613          	addi	a2,a2,1900 # ffffffffc0201640 <etext+0x5ac>
ffffffffc0200edc:	85ca                	mv	a1,s2
ffffffffc0200ede:	8526                	mv	a0,s1
ffffffffc0200ee0:	0d8000ef          	jal	ffffffffc0200fb8 <printfmt>
ffffffffc0200ee4:	b3c9                	j	ffffffffc0200ca6 <vprintfmt+0x34>
                printfmt(putch, putdat, "error %d", err);
ffffffffc0200ee6:	00000617          	auipc	a2,0x0
ffffffffc0200eea:	74a60613          	addi	a2,a2,1866 # ffffffffc0201630 <etext+0x59c>
ffffffffc0200eee:	85ca                	mv	a1,s2
ffffffffc0200ef0:	8526                	mv	a0,s1
ffffffffc0200ef2:	0c6000ef          	jal	ffffffffc0200fb8 <printfmt>
ffffffffc0200ef6:	bb45                	j	ffffffffc0200ca6 <vprintfmt+0x34>
    if (lflag >= 2) {
ffffffffc0200ef8:	4705                	li	a4,1
            precision = va_arg(ap, int);
ffffffffc0200efa:	008a0b93          	addi	s7,s4,8
    if (lflag >= 2) {
ffffffffc0200efe:	00f74363          	blt	a4,a5,ffffffffc0200f04 <vprintfmt+0x292>
    else if (lflag) {
ffffffffc0200f02:	cf81                	beqz	a5,ffffffffc0200f1a <vprintfmt+0x2a8>
        return va_arg(*ap, long);
ffffffffc0200f04:	000a3403          	ld	s0,0(s4)
            if ((long long)num < 0) {
ffffffffc0200f08:	02044b63          	bltz	s0,ffffffffc0200f3e <vprintfmt+0x2cc>
            num = getint(&ap, lflag);
ffffffffc0200f0c:	8622                	mv	a2,s0
ffffffffc0200f0e:	8a5e                	mv	s4,s7
ffffffffc0200f10:	46a9                	li	a3,10
ffffffffc0200f12:	b541                	j	ffffffffc0200d92 <vprintfmt+0x120>
            lflag ++;
ffffffffc0200f14:	2785                	addiw	a5,a5,1
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0200f16:	8462                	mv	s0,s8
            goto reswitch;
ffffffffc0200f18:	bb5d                	j	ffffffffc0200cce <vprintfmt+0x5c>
        return va_arg(*ap, int);
ffffffffc0200f1a:	000a2403          	lw	s0,0(s4)
ffffffffc0200f1e:	b7ed                	j	ffffffffc0200f08 <vprintfmt+0x296>
        return va_arg(*ap, unsigned int);
ffffffffc0200f20:	000a6603          	lwu	a2,0(s4)
ffffffffc0200f24:	46a1                	li	a3,8
ffffffffc0200f26:	8a2e                	mv	s4,a1
ffffffffc0200f28:	b5ad                	j	ffffffffc0200d92 <vprintfmt+0x120>
ffffffffc0200f2a:	000a6603          	lwu	a2,0(s4)
ffffffffc0200f2e:	46a9                	li	a3,10
ffffffffc0200f30:	8a2e                	mv	s4,a1
ffffffffc0200f32:	b585                	j	ffffffffc0200d92 <vprintfmt+0x120>
ffffffffc0200f34:	000a6603          	lwu	a2,0(s4)
ffffffffc0200f38:	46c1                	li	a3,16
ffffffffc0200f3a:	8a2e                	mv	s4,a1
ffffffffc0200f3c:	bd99                	j	ffffffffc0200d92 <vprintfmt+0x120>
                putch('-', putdat);
ffffffffc0200f3e:	85ca                	mv	a1,s2
ffffffffc0200f40:	02d00513          	li	a0,45
ffffffffc0200f44:	9482                	jalr	s1
                num = -(long long)num;
ffffffffc0200f46:	40800633          	neg	a2,s0
ffffffffc0200f4a:	8a5e                	mv	s4,s7
ffffffffc0200f4c:	46a9                	li	a3,10
ffffffffc0200f4e:	b591                	j	ffffffffc0200d92 <vprintfmt+0x120>
            if (width > 0 && padc != '-') {
ffffffffc0200f50:	e329                	bnez	a4,ffffffffc0200f92 <vprintfmt+0x320>
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0200f52:	02800793          	li	a5,40
ffffffffc0200f56:	853e                	mv	a0,a5
ffffffffc0200f58:	00000d97          	auipc	s11,0x0
ffffffffc0200f5c:	6d1d8d93          	addi	s11,s11,1745 # ffffffffc0201629 <etext+0x595>
ffffffffc0200f60:	b5f5                	j	ffffffffc0200e4c <vprintfmt+0x1da>
                for (width -= strnlen(p, precision); width > 0; width --) {
ffffffffc0200f62:	85e6                	mv	a1,s9
ffffffffc0200f64:	856e                	mv	a0,s11
ffffffffc0200f66:	0a4000ef          	jal	ffffffffc020100a <strnlen>
ffffffffc0200f6a:	40ad0d3b          	subw	s10,s10,a0
ffffffffc0200f6e:	01a05863          	blez	s10,ffffffffc0200f7e <vprintfmt+0x30c>
                    putch(padc, putdat);
ffffffffc0200f72:	85ca                	mv	a1,s2
ffffffffc0200f74:	8522                	mv	a0,s0
                for (width -= strnlen(p, precision); width > 0; width --) {
ffffffffc0200f76:	3d7d                	addiw	s10,s10,-1
                    putch(padc, putdat);
ffffffffc0200f78:	9482                	jalr	s1
                for (width -= strnlen(p, precision); width > 0; width --) {
ffffffffc0200f7a:	fe0d1ce3          	bnez	s10,ffffffffc0200f72 <vprintfmt+0x300>
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0200f7e:	000dc783          	lbu	a5,0(s11)
ffffffffc0200f82:	0007851b          	sext.w	a0,a5
ffffffffc0200f86:	ec0792e3          	bnez	a5,ffffffffc0200e4a <vprintfmt+0x1d8>
            if ((p = va_arg(ap, char *)) == NULL) {
ffffffffc0200f8a:	6a22                	ld	s4,8(sp)
ffffffffc0200f8c:	bb29                	j	ffffffffc0200ca6 <vprintfmt+0x34>
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0200f8e:	8462                	mv	s0,s8
ffffffffc0200f90:	bbd9                	j	ffffffffc0200d66 <vprintfmt+0xf4>
                for (width -= strnlen(p, precision); width > 0; width --) {
ffffffffc0200f92:	85e6                	mv	a1,s9
ffffffffc0200f94:	00000517          	auipc	a0,0x0
ffffffffc0200f98:	69450513          	addi	a0,a0,1684 # ffffffffc0201628 <etext+0x594>
ffffffffc0200f9c:	06e000ef          	jal	ffffffffc020100a <strnlen>
ffffffffc0200fa0:	40ad0d3b          	subw	s10,s10,a0
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0200fa4:	02800793          	li	a5,40
                p = "(null)";
ffffffffc0200fa8:	00000d97          	auipc	s11,0x0
ffffffffc0200fac:	680d8d93          	addi	s11,s11,1664 # ffffffffc0201628 <etext+0x594>
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0200fb0:	853e                	mv	a0,a5
                for (width -= strnlen(p, precision); width > 0; width --) {
ffffffffc0200fb2:	fda040e3          	bgtz	s10,ffffffffc0200f72 <vprintfmt+0x300>
ffffffffc0200fb6:	bd51                	j	ffffffffc0200e4a <vprintfmt+0x1d8>

ffffffffc0200fb8 <printfmt>:
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...) {
ffffffffc0200fb8:	715d                	addi	sp,sp,-80
    va_start(ap, fmt);
ffffffffc0200fba:	02810313          	addi	t1,sp,40
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...) {
ffffffffc0200fbe:	f436                	sd	a3,40(sp)
    vprintfmt(putch, putdat, fmt, ap);
ffffffffc0200fc0:	869a                	mv	a3,t1
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...) {
ffffffffc0200fc2:	ec06                	sd	ra,24(sp)
ffffffffc0200fc4:	f83a                	sd	a4,48(sp)
ffffffffc0200fc6:	fc3e                	sd	a5,56(sp)
ffffffffc0200fc8:	e0c2                	sd	a6,64(sp)
ffffffffc0200fca:	e4c6                	sd	a7,72(sp)
    va_start(ap, fmt);
ffffffffc0200fcc:	e41a                	sd	t1,8(sp)
    vprintfmt(putch, putdat, fmt, ap);
ffffffffc0200fce:	ca5ff0ef          	jal	ffffffffc0200c72 <vprintfmt>
}
ffffffffc0200fd2:	60e2                	ld	ra,24(sp)
ffffffffc0200fd4:	6161                	addi	sp,sp,80
ffffffffc0200fd6:	8082                	ret

ffffffffc0200fd8 <sbi_console_putchar>:
uint64_t SBI_REMOTE_SFENCE_VMA_ASID = 7;
uint64_t SBI_SHUTDOWN = 8;

uint64_t sbi_call(uint64_t sbi_type, uint64_t arg0, uint64_t arg1, uint64_t arg2) {
    uint64_t ret_val;
    __asm__ volatile (
ffffffffc0200fd8:	00004717          	auipc	a4,0x4
ffffffffc0200fdc:	03873703          	ld	a4,56(a4) # ffffffffc0205010 <SBI_CONSOLE_PUTCHAR>
ffffffffc0200fe0:	4781                	li	a5,0
ffffffffc0200fe2:	88ba                	mv	a7,a4
ffffffffc0200fe4:	852a                	mv	a0,a0
ffffffffc0200fe6:	85be                	mv	a1,a5
ffffffffc0200fe8:	863e                	mv	a2,a5
ffffffffc0200fea:	00000073          	ecall
ffffffffc0200fee:	87aa                	mv	a5,a0
    return ret_val;
}

void sbi_console_putchar(unsigned char ch) {
    sbi_call(SBI_CONSOLE_PUTCHAR, ch, 0, 0);
}
ffffffffc0200ff0:	8082                	ret

ffffffffc0200ff2 <strlen>:
 * The strlen() function returns the length of string @s.
 * */
size_t
strlen(const char *s) {
    size_t cnt = 0;
    while (*s ++ != '\0') {
ffffffffc0200ff2:	00054783          	lbu	a5,0(a0)
ffffffffc0200ff6:	cb81                	beqz	a5,ffffffffc0201006 <strlen+0x14>
    size_t cnt = 0;
ffffffffc0200ff8:	4781                	li	a5,0
        cnt ++;
ffffffffc0200ffa:	0785                	addi	a5,a5,1
    while (*s ++ != '\0') {
ffffffffc0200ffc:	00f50733          	add	a4,a0,a5
ffffffffc0201000:	00074703          	lbu	a4,0(a4)
ffffffffc0201004:	fb7d                	bnez	a4,ffffffffc0200ffa <strlen+0x8>
    }
    return cnt;
}
ffffffffc0201006:	853e                	mv	a0,a5
ffffffffc0201008:	8082                	ret

ffffffffc020100a <strnlen>:
 * @len if there is no '\0' character among the first @len characters
 * pointed by @s.
 * */
size_t
strnlen(const char *s, size_t len) {
    size_t cnt = 0;
ffffffffc020100a:	4781                	li	a5,0
    while (cnt < len && *s ++ != '\0') {
ffffffffc020100c:	e589                	bnez	a1,ffffffffc0201016 <strnlen+0xc>
ffffffffc020100e:	a811                	j	ffffffffc0201022 <strnlen+0x18>
        cnt ++;
ffffffffc0201010:	0785                	addi	a5,a5,1
    while (cnt < len && *s ++ != '\0') {
ffffffffc0201012:	00f58863          	beq	a1,a5,ffffffffc0201022 <strnlen+0x18>
ffffffffc0201016:	00f50733          	add	a4,a0,a5
ffffffffc020101a:	00074703          	lbu	a4,0(a4)
ffffffffc020101e:	fb6d                	bnez	a4,ffffffffc0201010 <strnlen+0x6>
ffffffffc0201020:	85be                	mv	a1,a5
    }
    return cnt;
}
ffffffffc0201022:	852e                	mv	a0,a1
ffffffffc0201024:	8082                	ret

ffffffffc0201026 <strcmp>:
int
strcmp(const char *s1, const char *s2) {
#ifdef __HAVE_ARCH_STRCMP
    return __strcmp(s1, s2);
#else
    while (*s1 != '\0' && *s1 == *s2) {
ffffffffc0201026:	00054783          	lbu	a5,0(a0)
ffffffffc020102a:	e791                	bnez	a5,ffffffffc0201036 <strcmp+0x10>
ffffffffc020102c:	a01d                	j	ffffffffc0201052 <strcmp+0x2c>
ffffffffc020102e:	00054783          	lbu	a5,0(a0)
ffffffffc0201032:	cb99                	beqz	a5,ffffffffc0201048 <strcmp+0x22>
ffffffffc0201034:	0585                	addi	a1,a1,1
ffffffffc0201036:	0005c703          	lbu	a4,0(a1)
        s1 ++, s2 ++;
ffffffffc020103a:	0505                	addi	a0,a0,1
    while (*s1 != '\0' && *s1 == *s2) {
ffffffffc020103c:	fef709e3          	beq	a4,a5,ffffffffc020102e <strcmp+0x8>
    }
    return (int)((unsigned char)*s1 - (unsigned char)*s2);
ffffffffc0201040:	0007851b          	sext.w	a0,a5
#endif /* __HAVE_ARCH_STRCMP */
}
ffffffffc0201044:	9d19                	subw	a0,a0,a4
ffffffffc0201046:	8082                	ret
    return (int)((unsigned char)*s1 - (unsigned char)*s2);
ffffffffc0201048:	0015c703          	lbu	a4,1(a1)
ffffffffc020104c:	4501                	li	a0,0
}
ffffffffc020104e:	9d19                	subw	a0,a0,a4
ffffffffc0201050:	8082                	ret
    return (int)((unsigned char)*s1 - (unsigned char)*s2);
ffffffffc0201052:	0005c703          	lbu	a4,0(a1)
ffffffffc0201056:	4501                	li	a0,0
ffffffffc0201058:	b7f5                	j	ffffffffc0201044 <strcmp+0x1e>

ffffffffc020105a <strncmp>:
 * the characters differ, until a terminating null-character is reached, or
 * until @n characters match in both strings, whichever happens first.
 * */
int
strncmp(const char *s1, const char *s2, size_t n) {
    while (n > 0 && *s1 != '\0' && *s1 == *s2) {
ffffffffc020105a:	ce01                	beqz	a2,ffffffffc0201072 <strncmp+0x18>
ffffffffc020105c:	00054783          	lbu	a5,0(a0)
        n --, s1 ++, s2 ++;
ffffffffc0201060:	167d                	addi	a2,a2,-1
    while (n > 0 && *s1 != '\0' && *s1 == *s2) {
ffffffffc0201062:	cb91                	beqz	a5,ffffffffc0201076 <strncmp+0x1c>
ffffffffc0201064:	0005c703          	lbu	a4,0(a1)
ffffffffc0201068:	00f71763          	bne	a4,a5,ffffffffc0201076 <strncmp+0x1c>
        n --, s1 ++, s2 ++;
ffffffffc020106c:	0505                	addi	a0,a0,1
ffffffffc020106e:	0585                	addi	a1,a1,1
    while (n > 0 && *s1 != '\0' && *s1 == *s2) {
ffffffffc0201070:	f675                	bnez	a2,ffffffffc020105c <strncmp+0x2>
    }
    return (n == 0) ? 0 : (int)((unsigned char)*s1 - (unsigned char)*s2);
ffffffffc0201072:	4501                	li	a0,0
ffffffffc0201074:	8082                	ret
ffffffffc0201076:	00054503          	lbu	a0,0(a0)
ffffffffc020107a:	0005c783          	lbu	a5,0(a1)
ffffffffc020107e:	9d1d                	subw	a0,a0,a5
}
ffffffffc0201080:	8082                	ret

ffffffffc0201082 <memset>:
memset(void *s, char c, size_t n) {
#ifdef __HAVE_ARCH_MEMSET
    return __memset(s, c, n);
#else
    char *p = s;
    while (n -- > 0) {
ffffffffc0201082:	ca01                	beqz	a2,ffffffffc0201092 <memset+0x10>
ffffffffc0201084:	962a                	add	a2,a2,a0
    char *p = s;
ffffffffc0201086:	87aa                	mv	a5,a0
        *p ++ = c;
ffffffffc0201088:	0785                	addi	a5,a5,1
ffffffffc020108a:	feb78fa3          	sb	a1,-1(a5)
    while (n -- > 0) {
ffffffffc020108e:	fef61de3          	bne	a2,a5,ffffffffc0201088 <memset+0x6>
    }
    return s;
#endif /* __HAVE_ARCH_MEMSET */
}
ffffffffc0201092:	8082                	ret
